Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES2.cpp: Validation functions for OpenGL ES 2.0 entry point parameters |
| 8 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES2_autogen.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 10 | |
| 11 | #include <cstdint> |
| 12 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 13 | #include "common/mathutil.h" |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 14 | #include "common/string_utils.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 15 | #include "common/utilities.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 16 | #include "libANGLE/Context.h" |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 17 | #include "libANGLE/ErrorStrings.h" |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 18 | #include "libANGLE/Fence.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 19 | #include "libANGLE/Framebuffer.h" |
| 20 | #include "libANGLE/FramebufferAttachment.h" |
| 21 | #include "libANGLE/Renderbuffer.h" |
| 22 | #include "libANGLE/Shader.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/Texture.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 24 | #include "libANGLE/Uniform.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 25 | #include "libANGLE/VertexArray.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 26 | #include "libANGLE/formatutils.h" |
| 27 | #include "libANGLE/validationES.h" |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 28 | #include "libANGLE/validationES2.h" |
| 29 | #include "libANGLE/validationES3_autogen.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 30 | |
| 31 | namespace gl |
| 32 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 33 | using namespace err; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 34 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 35 | namespace |
| 36 | { |
| 37 | |
| 38 | bool IsPartialBlit(gl::Context *context, |
| 39 | const FramebufferAttachment *readBuffer, |
| 40 | const FramebufferAttachment *writeBuffer, |
| 41 | GLint srcX0, |
| 42 | GLint srcY0, |
| 43 | GLint srcX1, |
| 44 | GLint srcY1, |
| 45 | GLint dstX0, |
| 46 | GLint dstY0, |
| 47 | GLint dstX1, |
| 48 | GLint dstY1) |
| 49 | { |
| 50 | const Extents &writeSize = writeBuffer->getSize(); |
| 51 | const Extents &readSize = readBuffer->getSize(); |
| 52 | |
| 53 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width || |
| 54 | dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height) |
| 55 | { |
| 56 | return true; |
| 57 | } |
| 58 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 59 | if (context->getState().isScissorTestEnabled()) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 60 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 61 | const Rectangle &scissor = context->getState().getScissor(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 62 | return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width || |
| 63 | scissor.height < writeSize.height; |
| 64 | } |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 69 | template <typename T> |
| 70 | bool ValidatePathInstances(gl::Context *context, |
| 71 | GLsizei numPaths, |
| 72 | const void *paths, |
| 73 | GLuint pathBase) |
| 74 | { |
| 75 | const auto *array = static_cast<const T *>(paths); |
| 76 | |
| 77 | for (GLsizei i = 0; i < numPaths; ++i) |
| 78 | { |
| 79 | const GLuint pathName = array[i] + pathBase; |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 80 | if (context->isPathGenerated(pathName) && !context->isPath(pathName)) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 81 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 82 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 83 | return false; |
| 84 | } |
| 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool ValidateInstancedPathParameters(gl::Context *context, |
| 90 | GLsizei numPaths, |
| 91 | GLenum pathNameType, |
| 92 | const void *paths, |
| 93 | GLuint pathBase, |
| 94 | GLenum transformType, |
| 95 | const GLfloat *transformValues) |
| 96 | { |
| 97 | if (!context->getExtensions().pathRendering) |
| 98 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 99 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | if (paths == nullptr) |
| 104 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 105 | context->validationError(GL_INVALID_VALUE, kInvalidPathNameArray); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 106 | return false; |
| 107 | } |
| 108 | |
| 109 | if (numPaths < 0) |
| 110 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 111 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumPaths); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 112 | return false; |
| 113 | } |
| 114 | |
| 115 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths)) |
| 116 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 117 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 118 | return false; |
| 119 | } |
| 120 | |
| 121 | std::uint32_t pathNameTypeSize = 0; |
| 122 | std::uint32_t componentCount = 0; |
| 123 | |
| 124 | switch (pathNameType) |
| 125 | { |
| 126 | case GL_UNSIGNED_BYTE: |
| 127 | pathNameTypeSize = sizeof(GLubyte); |
| 128 | if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase)) |
| 129 | return false; |
| 130 | break; |
| 131 | |
| 132 | case GL_BYTE: |
| 133 | pathNameTypeSize = sizeof(GLbyte); |
| 134 | if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase)) |
| 135 | return false; |
| 136 | break; |
| 137 | |
| 138 | case GL_UNSIGNED_SHORT: |
| 139 | pathNameTypeSize = sizeof(GLushort); |
| 140 | if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase)) |
| 141 | return false; |
| 142 | break; |
| 143 | |
| 144 | case GL_SHORT: |
| 145 | pathNameTypeSize = sizeof(GLshort); |
| 146 | if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase)) |
| 147 | return false; |
| 148 | break; |
| 149 | |
| 150 | case GL_UNSIGNED_INT: |
| 151 | pathNameTypeSize = sizeof(GLuint); |
| 152 | if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase)) |
| 153 | return false; |
| 154 | break; |
| 155 | |
| 156 | case GL_INT: |
| 157 | pathNameTypeSize = sizeof(GLint); |
| 158 | if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase)) |
| 159 | return false; |
| 160 | break; |
| 161 | |
| 162 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 163 | context->validationError(GL_INVALID_ENUM, kInvalidPathNameType); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 164 | return false; |
| 165 | } |
| 166 | |
| 167 | switch (transformType) |
| 168 | { |
| 169 | case GL_NONE: |
| 170 | componentCount = 0; |
| 171 | break; |
| 172 | case GL_TRANSLATE_X_CHROMIUM: |
| 173 | case GL_TRANSLATE_Y_CHROMIUM: |
| 174 | componentCount = 1; |
| 175 | break; |
| 176 | case GL_TRANSLATE_2D_CHROMIUM: |
| 177 | componentCount = 2; |
| 178 | break; |
| 179 | case GL_TRANSLATE_3D_CHROMIUM: |
| 180 | componentCount = 3; |
| 181 | break; |
| 182 | case GL_AFFINE_2D_CHROMIUM: |
| 183 | case GL_TRANSPOSE_AFFINE_2D_CHROMIUM: |
| 184 | componentCount = 6; |
| 185 | break; |
| 186 | case GL_AFFINE_3D_CHROMIUM: |
| 187 | case GL_TRANSPOSE_AFFINE_3D_CHROMIUM: |
| 188 | componentCount = 12; |
| 189 | break; |
| 190 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 191 | context->validationError(GL_INVALID_ENUM, kInvalidTransformation); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 192 | return false; |
| 193 | } |
| 194 | if (componentCount != 0 && transformValues == nullptr) |
| 195 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 196 | context->validationError(GL_INVALID_VALUE, kNoTransformArray); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 197 | return false; |
| 198 | } |
| 199 | |
| 200 | angle::CheckedNumeric<std::uint32_t> checkedSize(0); |
| 201 | checkedSize += (numPaths * pathNameTypeSize); |
| 202 | checkedSize += (numPaths * sizeof(GLfloat) * componentCount); |
| 203 | if (!checkedSize.IsValid()) |
| 204 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 205 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 206 | return false; |
| 207 | } |
| 208 | |
| 209 | return true; |
| 210 | } |
| 211 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 212 | bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 213 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 214 | // Table 1.1 from the CHROMIUM_copy_texture spec |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 215 | switch (GetUnsizedFormat(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 216 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 217 | case GL_RED: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 218 | case GL_ALPHA: |
| 219 | case GL_LUMINANCE: |
| 220 | case GL_LUMINANCE_ALPHA: |
| 221 | case GL_RGB: |
| 222 | case GL_RGBA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 223 | case GL_RGB8: |
| 224 | case GL_RGBA8: |
| 225 | case GL_BGRA_EXT: |
| 226 | case GL_BGRA8_EXT: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 227 | return true; |
| 228 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 229 | default: |
| 230 | return false; |
| 231 | } |
| 232 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 233 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 234 | bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat) |
| 235 | { |
| 236 | return IsValidCopyTextureSourceInternalFormatEnum(internalFormat); |
| 237 | } |
| 238 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 239 | bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat) |
| 240 | { |
| 241 | // Table 1.0 from the CHROMIUM_copy_texture spec |
| 242 | switch (internalFormat) |
| 243 | { |
| 244 | case GL_RGB: |
| 245 | case GL_RGBA: |
| 246 | case GL_RGB8: |
| 247 | case GL_RGBA8: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 248 | case GL_BGRA_EXT: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 249 | case GL_BGRA8_EXT: |
| 250 | case GL_SRGB_EXT: |
| 251 | case GL_SRGB_ALPHA_EXT: |
| 252 | case GL_R8: |
| 253 | case GL_R8UI: |
| 254 | case GL_RG8: |
| 255 | case GL_RG8UI: |
| 256 | case GL_SRGB8: |
| 257 | case GL_RGB565: |
| 258 | case GL_RGB8UI: |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 259 | case GL_RGB10_A2: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 260 | case GL_SRGB8_ALPHA8: |
| 261 | case GL_RGB5_A1: |
| 262 | case GL_RGBA4: |
| 263 | case GL_RGBA8UI: |
| 264 | case GL_RGB9_E5: |
| 265 | case GL_R16F: |
| 266 | case GL_R32F: |
| 267 | case GL_RG16F: |
| 268 | case GL_RG32F: |
| 269 | case GL_RGB16F: |
| 270 | case GL_RGB32F: |
| 271 | case GL_RGBA16F: |
| 272 | case GL_RGBA32F: |
| 273 | case GL_R11F_G11F_B10F: |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 274 | case GL_LUMINANCE: |
| 275 | case GL_LUMINANCE_ALPHA: |
| 276 | case GL_ALPHA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 277 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 278 | |
| 279 | default: |
| 280 | return false; |
| 281 | } |
| 282 | } |
| 283 | |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 284 | bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat) |
| 285 | { |
| 286 | return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat); |
| 287 | } |
| 288 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 289 | bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type) |
| 290 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 291 | if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 292 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 293 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 294 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 297 | if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat)) |
| 298 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 299 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 303 | const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type); |
| 304 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 305 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 306 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 307 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return true; |
| 311 | } |
| 312 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 313 | bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 314 | { |
| 315 | switch (target) |
| 316 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 317 | case TextureTarget::_2D: |
| 318 | case TextureTarget::CubeMapNegativeX: |
| 319 | case TextureTarget::CubeMapNegativeY: |
| 320 | case TextureTarget::CubeMapNegativeZ: |
| 321 | case TextureTarget::CubeMapPositiveX: |
| 322 | case TextureTarget::CubeMapPositiveY: |
| 323 | case TextureTarget::CubeMapPositiveZ: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 324 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 325 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 326 | case TextureTarget::Rectangle: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 327 | return context->getExtensions().textureRectangle; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 328 | |
| 329 | default: |
| 330 | return false; |
| 331 | } |
| 332 | } |
| 333 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 334 | bool IsValidCopyTextureDestinationTarget(Context *context, |
| 335 | TextureType textureType, |
| 336 | TextureTarget target) |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 337 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 338 | return TextureTargetToType(target) == textureType; |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 341 | bool IsValidCopyTextureSourceTarget(Context *context, TextureType type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 342 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 343 | switch (type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 344 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 345 | case TextureType::_2D: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 346 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 347 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 348 | return context->getExtensions().textureRectangle; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 349 | case TextureType::External: |
| 350 | return context->getExtensions().eglImageExternal; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 351 | default: |
| 352 | return false; |
| 353 | } |
| 354 | } |
| 355 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 356 | bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 357 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 358 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 359 | { |
| 360 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 363 | if (level > 0 && context->getClientVersion() < ES_3_0) |
| 364 | { |
| 365 | return false; |
| 366 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 367 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 368 | return true; |
| 369 | } |
| 370 | |
| 371 | bool IsValidCopyTextureDestinationLevel(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 372 | TextureType type, |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 373 | GLint level, |
| 374 | GLsizei width, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 375 | GLsizei height, |
| 376 | bool isSubImage) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 377 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 378 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 379 | { |
| 380 | return false; |
| 381 | } |
| 382 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 383 | if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage)) |
| 384 | { |
| 385 | return false; |
| 386 | } |
| 387 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 388 | const Caps &caps = context->getCaps(); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 389 | switch (type) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 390 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 391 | case TextureType::_2D: |
| 392 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 393 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
| 394 | case TextureType::Rectangle: |
| 395 | ASSERT(level == 0); |
| 396 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 397 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 398 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 399 | case TextureType::CubeMap: |
| 400 | return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) && |
| 401 | static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level); |
| 402 | default: |
| 403 | return true; |
| 404 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 407 | bool IsValidStencilFunc(GLenum func) |
| 408 | { |
| 409 | switch (func) |
| 410 | { |
| 411 | case GL_NEVER: |
| 412 | case GL_ALWAYS: |
| 413 | case GL_LESS: |
| 414 | case GL_LEQUAL: |
| 415 | case GL_EQUAL: |
| 416 | case GL_GEQUAL: |
| 417 | case GL_GREATER: |
| 418 | case GL_NOTEQUAL: |
| 419 | return true; |
| 420 | |
| 421 | default: |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | bool IsValidStencilFace(GLenum face) |
| 427 | { |
| 428 | switch (face) |
| 429 | { |
| 430 | case GL_FRONT: |
| 431 | case GL_BACK: |
| 432 | case GL_FRONT_AND_BACK: |
| 433 | return true; |
| 434 | |
| 435 | default: |
| 436 | return false; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | bool IsValidStencilOp(GLenum op) |
| 441 | { |
| 442 | switch (op) |
| 443 | { |
| 444 | case GL_ZERO: |
| 445 | case GL_KEEP: |
| 446 | case GL_REPLACE: |
| 447 | case GL_INCR: |
| 448 | case GL_DECR: |
| 449 | case GL_INVERT: |
| 450 | case GL_INCR_WRAP: |
| 451 | case GL_DECR_WRAP: |
| 452 | return true; |
| 453 | |
| 454 | default: |
| 455 | return false; |
| 456 | } |
| 457 | } |
| 458 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 459 | bool ValidateES2CopyTexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 460 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 461 | GLint level, |
| 462 | GLenum internalformat, |
| 463 | bool isSubImage, |
| 464 | GLint xoffset, |
| 465 | GLint yoffset, |
| 466 | GLint x, |
| 467 | GLint y, |
| 468 | GLsizei width, |
| 469 | GLsizei height, |
| 470 | GLint border) |
| 471 | { |
| 472 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 474 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 475 | return false; |
| 476 | } |
| 477 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 478 | TextureType texType = TextureTargetToType(target); |
| 479 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 480 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 481 | // Error is already handled. |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 482 | return false; |
| 483 | } |
| 484 | |
| 485 | Format textureFormat = Format::Invalid(); |
| 486 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 487 | xoffset, yoffset, 0, x, y, width, height, border, |
| 488 | &textureFormat)) |
| 489 | { |
| 490 | return false; |
| 491 | } |
| 492 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 493 | const gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 494 | GLenum colorbufferFormat = |
| 495 | framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat; |
| 496 | const auto &formatInfo = *textureFormat.info; |
| 497 | |
| 498 | // [OpenGL ES 2.0.24] table 3.9 |
| 499 | if (isSubImage) |
| 500 | { |
| 501 | switch (formatInfo.format) |
| 502 | { |
| 503 | case GL_ALPHA: |
| 504 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 505 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 506 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 507 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 508 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 509 | return false; |
| 510 | } |
| 511 | break; |
| 512 | case GL_LUMINANCE: |
| 513 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 514 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 515 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 516 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT && |
| 517 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 518 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 519 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 520 | return false; |
| 521 | } |
| 522 | break; |
| 523 | case GL_RED_EXT: |
| 524 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 525 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 526 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 527 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F && |
| 528 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 529 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 530 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 531 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 532 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 533 | return false; |
| 534 | } |
| 535 | break; |
| 536 | case GL_RG_EXT: |
| 537 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 538 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 539 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 540 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 541 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 542 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 543 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 544 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | break; |
| 548 | case GL_RGB: |
| 549 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 550 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 551 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 552 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 553 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 554 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 555 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 556 | return false; |
| 557 | } |
| 558 | break; |
| 559 | case GL_LUMINANCE_ALPHA: |
| 560 | case GL_RGBA: |
| 561 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 562 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F && |
| 563 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 564 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 565 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 566 | return false; |
| 567 | } |
| 568 | break; |
| 569 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 570 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 571 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 572 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 573 | case GL_ETC1_RGB8_OES: |
| 574 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 575 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 576 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 577 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 578 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 579 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 580 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 581 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 582 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 583 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 584 | return false; |
| 585 | case GL_DEPTH_COMPONENT: |
| 586 | case GL_DEPTH_STENCIL_OES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 587 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 588 | return false; |
| 589 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 590 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | |
| 594 | if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat) |
| 595 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 596 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 597 | return false; |
| 598 | } |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | switch (internalformat) |
| 603 | { |
| 604 | case GL_ALPHA: |
| 605 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
| 606 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 607 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 608 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 609 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 610 | return false; |
| 611 | } |
| 612 | break; |
| 613 | case GL_LUMINANCE: |
| 614 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 615 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 616 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 617 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 618 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 619 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 620 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 621 | return false; |
| 622 | } |
| 623 | break; |
| 624 | case GL_RED_EXT: |
| 625 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 626 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 627 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 628 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 629 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 630 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 631 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 632 | return false; |
| 633 | } |
| 634 | break; |
| 635 | case GL_RG_EXT: |
| 636 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 637 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 638 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 639 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 640 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 641 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 642 | return false; |
| 643 | } |
| 644 | break; |
| 645 | case GL_RGB: |
| 646 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 647 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 648 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 649 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 650 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 651 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 652 | return false; |
| 653 | } |
| 654 | break; |
| 655 | case GL_LUMINANCE_ALPHA: |
| 656 | case GL_RGBA: |
| 657 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 658 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 659 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 660 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 661 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 662 | return false; |
| 663 | } |
| 664 | break; |
| 665 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 666 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 667 | if (context->getExtensions().textureCompressionDXT1) |
| 668 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 669 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 670 | return false; |
| 671 | } |
| 672 | else |
| 673 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 674 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 675 | return false; |
| 676 | } |
| 677 | break; |
| 678 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 679 | if (context->getExtensions().textureCompressionDXT3) |
| 680 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 681 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 682 | return false; |
| 683 | } |
| 684 | else |
| 685 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 686 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 687 | return false; |
| 688 | } |
| 689 | break; |
| 690 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 691 | if (context->getExtensions().textureCompressionDXT5) |
| 692 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 693 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | else |
| 697 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 698 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 699 | return false; |
| 700 | } |
| 701 | break; |
| 702 | case GL_ETC1_RGB8_OES: |
| 703 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 704 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 705 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 706 | return false; |
| 707 | } |
| 708 | else |
| 709 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 710 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 711 | return false; |
| 712 | } |
| 713 | break; |
| 714 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 715 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 716 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 717 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 718 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 719 | if (context->getExtensions().lossyETCDecode) |
| 720 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 721 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 722 | return false; |
| 723 | } |
| 724 | else |
| 725 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 726 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 727 | return false; |
| 728 | } |
| 729 | break; |
| 730 | case GL_DEPTH_COMPONENT: |
| 731 | case GL_DEPTH_COMPONENT16: |
| 732 | case GL_DEPTH_COMPONENT32_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 733 | if (context->getExtensions().depthTextureAny()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 734 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 735 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 736 | return false; |
| 737 | } |
| 738 | else |
| 739 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 740 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 741 | return false; |
| 742 | } |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 743 | break; |
| 744 | case GL_DEPTH_STENCIL_OES: |
| 745 | case GL_DEPTH24_STENCIL8_OES: |
| 746 | if (context->getExtensions().depthTextureAny() || |
| 747 | context->getExtensions().packedDepthStencil) |
| 748 | { |
| 749 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
| 750 | return false; |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 755 | return false; |
| 756 | } |
| 757 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 758 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 759 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 760 | return false; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 765 | return (width > 0 && height > 0); |
| 766 | } |
| 767 | |
| 768 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 769 | { |
| 770 | switch (cap) |
| 771 | { |
| 772 | // EXT_multisample_compatibility |
| 773 | case GL_MULTISAMPLE_EXT: |
| 774 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 775 | return context->getExtensions().multisampleCompatibility; |
| 776 | |
| 777 | case GL_CULL_FACE: |
| 778 | case GL_POLYGON_OFFSET_FILL: |
| 779 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 780 | case GL_SAMPLE_COVERAGE: |
| 781 | case GL_SCISSOR_TEST: |
| 782 | case GL_STENCIL_TEST: |
| 783 | case GL_DEPTH_TEST: |
| 784 | case GL_BLEND: |
| 785 | case GL_DITHER: |
| 786 | return true; |
| 787 | |
| 788 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 789 | case GL_RASTERIZER_DISCARD: |
| 790 | return (context->getClientMajorVersion() >= 3); |
| 791 | |
| 792 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 793 | case GL_DEBUG_OUTPUT: |
| 794 | return context->getExtensions().debug; |
| 795 | |
| 796 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 797 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 798 | |
| 799 | case GL_CLIENT_ARRAYS_ANGLE: |
| 800 | return queryOnly && context->getExtensions().clientArrays; |
| 801 | |
| 802 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 803 | return context->getExtensions().sRGBWriteControl; |
| 804 | |
| 805 | case GL_SAMPLE_MASK: |
| 806 | return context->getClientVersion() >= Version(3, 1); |
| 807 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 808 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 809 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 810 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 811 | // GLES1 emulation: GLES1-specific caps |
| 812 | case GL_ALPHA_TEST: |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 813 | case GL_VERTEX_ARRAY: |
| 814 | case GL_NORMAL_ARRAY: |
| 815 | case GL_COLOR_ARRAY: |
| 816 | case GL_TEXTURE_COORD_ARRAY: |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 817 | case GL_TEXTURE_2D: |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 818 | case GL_LIGHTING: |
| 819 | case GL_LIGHT0: |
| 820 | case GL_LIGHT1: |
| 821 | case GL_LIGHT2: |
| 822 | case GL_LIGHT3: |
| 823 | case GL_LIGHT4: |
| 824 | case GL_LIGHT5: |
| 825 | case GL_LIGHT6: |
| 826 | case GL_LIGHT7: |
| 827 | case GL_NORMALIZE: |
| 828 | case GL_RESCALE_NORMAL: |
| 829 | case GL_COLOR_MATERIAL: |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 830 | case GL_CLIP_PLANE0: |
| 831 | case GL_CLIP_PLANE1: |
| 832 | case GL_CLIP_PLANE2: |
| 833 | case GL_CLIP_PLANE3: |
| 834 | case GL_CLIP_PLANE4: |
| 835 | case GL_CLIP_PLANE5: |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 836 | case GL_FOG: |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 837 | case GL_POINT_SMOOTH: |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 838 | case GL_LINE_SMOOTH: |
| 839 | case GL_COLOR_LOGIC_OP: |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 840 | return context->getClientVersion() < Version(2, 0); |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 841 | case GL_POINT_SIZE_ARRAY_OES: |
| 842 | return context->getClientVersion() < Version(2, 0) && |
| 843 | context->getExtensions().pointSizeArray; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 844 | case GL_TEXTURE_CUBE_MAP: |
| 845 | return context->getClientVersion() < Version(2, 0) && |
| 846 | context->getExtensions().textureCubeMap; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 847 | case GL_POINT_SPRITE_OES: |
| 848 | return context->getClientVersion() < Version(2, 0) && |
| 849 | context->getExtensions().pointSprite; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 850 | default: |
| 851 | return false; |
| 852 | } |
| 853 | } |
| 854 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 855 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 856 | // 3.1. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 857 | bool IsValidESSLCharacter(unsigned char c) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 858 | { |
| 859 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 860 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && |
| 861 | c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 862 | { |
| 863 | return true; |
| 864 | } |
| 865 | |
| 866 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 867 | if (c >= 9 && c <= 13) |
| 868 | { |
| 869 | return true; |
| 870 | } |
| 871 | |
| 872 | return false; |
| 873 | } |
| 874 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 875 | bool IsValidESSLString(const char *str, size_t len) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 876 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 877 | for (size_t i = 0; i < len; i++) |
| 878 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 879 | if (!IsValidESSLCharacter(str[i])) |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 880 | { |
| 881 | return false; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 886 | } |
| 887 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 888 | bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed) |
| 889 | { |
| 890 | enum class ParseState |
| 891 | { |
| 892 | // Have not seen an ASCII non-whitespace character yet on |
| 893 | // this line. Possible that we might see a preprocessor |
| 894 | // directive. |
| 895 | BEGINING_OF_LINE, |
| 896 | |
| 897 | // Have seen at least one ASCII non-whitespace character |
| 898 | // on this line. |
| 899 | MIDDLE_OF_LINE, |
| 900 | |
| 901 | // Handling a preprocessor directive. Passes through all |
| 902 | // characters up to the end of the line. Disables comment |
| 903 | // processing. |
| 904 | IN_PREPROCESSOR_DIRECTIVE, |
| 905 | |
| 906 | // Handling a single-line comment. The comment text is |
| 907 | // replaced with a single space. |
| 908 | IN_SINGLE_LINE_COMMENT, |
| 909 | |
| 910 | // Handling a multi-line comment. Newlines are passed |
| 911 | // through to preserve line numbers. |
| 912 | IN_MULTI_LINE_COMMENT |
| 913 | }; |
| 914 | |
| 915 | ParseState state = ParseState::BEGINING_OF_LINE; |
| 916 | size_t pos = 0; |
| 917 | |
| 918 | while (pos < len) |
| 919 | { |
| 920 | char c = str[pos]; |
| 921 | char next = pos + 1 < len ? str[pos + 1] : 0; |
| 922 | |
| 923 | // Check for newlines |
| 924 | if (c == '\n' || c == '\r') |
| 925 | { |
| 926 | if (state != ParseState::IN_MULTI_LINE_COMMENT) |
| 927 | { |
| 928 | state = ParseState::BEGINING_OF_LINE; |
| 929 | } |
| 930 | |
| 931 | pos++; |
| 932 | continue; |
| 933 | } |
| 934 | |
| 935 | switch (state) |
| 936 | { |
| 937 | case ParseState::BEGINING_OF_LINE: |
| 938 | if (c == ' ') |
| 939 | { |
| 940 | // Maintain the BEGINING_OF_LINE state until a non-space is seen |
| 941 | pos++; |
| 942 | } |
| 943 | else if (c == '#') |
| 944 | { |
| 945 | state = ParseState::IN_PREPROCESSOR_DIRECTIVE; |
| 946 | pos++; |
| 947 | } |
| 948 | else |
| 949 | { |
| 950 | // Don't advance, re-process this character with the MIDDLE_OF_LINE state |
| 951 | state = ParseState::MIDDLE_OF_LINE; |
| 952 | } |
| 953 | break; |
| 954 | |
| 955 | case ParseState::MIDDLE_OF_LINE: |
| 956 | if (c == '/' && next == '/') |
| 957 | { |
| 958 | state = ParseState::IN_SINGLE_LINE_COMMENT; |
| 959 | pos++; |
| 960 | } |
| 961 | else if (c == '/' && next == '*') |
| 962 | { |
| 963 | state = ParseState::IN_MULTI_LINE_COMMENT; |
| 964 | pos++; |
| 965 | } |
| 966 | else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r')) |
| 967 | { |
| 968 | // Skip line continuation characters |
| 969 | } |
| 970 | else if (!IsValidESSLCharacter(c)) |
| 971 | { |
| 972 | return false; |
| 973 | } |
| 974 | pos++; |
| 975 | break; |
| 976 | |
| 977 | case ParseState::IN_PREPROCESSOR_DIRECTIVE: |
Bryan Bernhart (Intel Americas Inc) | 335d8bf | 2017-10-23 15:41:43 -0700 | [diff] [blame] | 978 | // Line-continuation characters may not be permitted. |
| 979 | // Otherwise, just pass it through. Do not parse comments in this state. |
| 980 | if (!lineContinuationAllowed && c == '\\') |
| 981 | { |
| 982 | return false; |
| 983 | } |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 984 | pos++; |
| 985 | break; |
| 986 | |
| 987 | case ParseState::IN_SINGLE_LINE_COMMENT: |
| 988 | // Line-continuation characters are processed before comment processing. |
| 989 | // Advance string if a new line character is immediately behind |
| 990 | // line-continuation character. |
| 991 | if (c == '\\' && (next == '\n' || next == '\r')) |
| 992 | { |
| 993 | pos++; |
| 994 | } |
| 995 | pos++; |
| 996 | break; |
| 997 | |
| 998 | case ParseState::IN_MULTI_LINE_COMMENT: |
| 999 | if (c == '*' && next == '/') |
| 1000 | { |
| 1001 | state = ParseState::MIDDLE_OF_LINE; |
| 1002 | pos++; |
| 1003 | } |
| 1004 | pos++; |
| 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | return true; |
| 1010 | } |
| 1011 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1012 | bool ValidateWebGLNamePrefix(Context *context, const GLchar *name) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1013 | { |
| 1014 | ASSERT(context->isWebGL()); |
| 1015 | |
| 1016 | // WebGL 1.0 [Section 6.16] GLSL Constructs |
| 1017 | // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. |
| 1018 | if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0) |
| 1019 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1020 | context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1021 | return false; |
| 1022 | } |
| 1023 | |
| 1024 | return true; |
| 1025 | } |
| 1026 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1027 | bool ValidateWebGLNameLength(Context *context, size_t length) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1028 | { |
| 1029 | ASSERT(context->isWebGL()); |
| 1030 | |
| 1031 | if (context->isWebGL1() && length > 256) |
| 1032 | { |
| 1033 | // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths |
| 1034 | // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute |
| 1035 | // locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1036 | context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1037 | |
| 1038 | return false; |
| 1039 | } |
| 1040 | else if (length > 1024) |
| 1041 | { |
| 1042 | // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of |
| 1043 | // uniform and attribute locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1044 | context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1045 | return false; |
| 1046 | } |
| 1047 | |
| 1048 | return true; |
| 1049 | } |
| 1050 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1051 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 1052 | { |
| 1053 | if (!context->getExtensions().pathRendering) |
| 1054 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1055 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1056 | return false; |
| 1057 | } |
| 1058 | |
| 1059 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 1060 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1061 | context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1062 | return false; |
| 1063 | } |
| 1064 | return true; |
| 1065 | } |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 1066 | |
| 1067 | bool ValidBlendFunc(const Context *context, GLenum val) |
| 1068 | { |
| 1069 | const gl::Extensions &ext = context->getExtensions(); |
| 1070 | |
| 1071 | // these are always valid for src and dst. |
| 1072 | switch (val) |
| 1073 | { |
| 1074 | case GL_ZERO: |
| 1075 | case GL_ONE: |
| 1076 | case GL_SRC_COLOR: |
| 1077 | case GL_ONE_MINUS_SRC_COLOR: |
| 1078 | case GL_DST_COLOR: |
| 1079 | case GL_ONE_MINUS_DST_COLOR: |
| 1080 | case GL_SRC_ALPHA: |
| 1081 | case GL_ONE_MINUS_SRC_ALPHA: |
| 1082 | case GL_DST_ALPHA: |
| 1083 | case GL_ONE_MINUS_DST_ALPHA: |
| 1084 | case GL_CONSTANT_COLOR: |
| 1085 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 1086 | case GL_CONSTANT_ALPHA: |
| 1087 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 1088 | return true; |
| 1089 | |
| 1090 | // EXT_blend_func_extended. |
| 1091 | case GL_SRC1_COLOR_EXT: |
| 1092 | case GL_SRC1_ALPHA_EXT: |
| 1093 | case GL_ONE_MINUS_SRC1_COLOR_EXT: |
| 1094 | case GL_ONE_MINUS_SRC1_ALPHA_EXT: |
| 1095 | case GL_SRC_ALPHA_SATURATE_EXT: |
| 1096 | return ext.blendFuncExtended; |
| 1097 | |
| 1098 | default: |
| 1099 | return false; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | bool ValidSrcBlendFunc(const Context *context, GLenum val) |
| 1104 | { |
| 1105 | if (ValidBlendFunc(context, val)) |
| 1106 | return true; |
| 1107 | |
| 1108 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1109 | return true; |
| 1110 | |
| 1111 | return false; |
| 1112 | } |
| 1113 | |
| 1114 | bool ValidDstBlendFunc(const Context *context, GLenum val) |
| 1115 | { |
| 1116 | if (ValidBlendFunc(context, val)) |
| 1117 | return true; |
| 1118 | |
| 1119 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1120 | { |
| 1121 | if (context->getClientMajorVersion() >= 3) |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
| 1125 | return false; |
| 1126 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1127 | } // anonymous namespace |
| 1128 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1129 | bool ValidateES2TexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1130 | TextureTarget target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1131 | GLint level, |
| 1132 | GLenum internalformat, |
| 1133 | bool isCompressed, |
| 1134 | bool isSubImage, |
| 1135 | GLint xoffset, |
| 1136 | GLint yoffset, |
| 1137 | GLsizei width, |
| 1138 | GLsizei height, |
| 1139 | GLint border, |
| 1140 | GLenum format, |
| 1141 | GLenum type, |
| 1142 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1143 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1144 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1145 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1146 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1147 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1148 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1151 | TextureType texType = TextureTargetToType(target); |
| 1152 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1153 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1154 | // Error already handled. |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1155 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1156 | } |
| 1157 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1158 | if (!ValidMipLevel(context, texType, level)) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1159 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1160 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1161 | return false; |
| 1162 | } |
| 1163 | |
| 1164 | if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width || |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1165 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1166 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1167 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1168 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1171 | const gl::Caps &caps = context->getCaps(); |
| 1172 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1173 | switch (texType) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1174 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1175 | case TextureType::_2D: |
| 1176 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 1177 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 1178 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1179 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1180 | return false; |
| 1181 | } |
| 1182 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1183 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1184 | case TextureType::Rectangle: |
| 1185 | ASSERT(level == 0); |
| 1186 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1187 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1188 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1189 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1190 | return false; |
| 1191 | } |
| 1192 | if (isCompressed) |
| 1193 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1194 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1195 | return false; |
| 1196 | } |
| 1197 | break; |
| 1198 | |
| 1199 | case TextureType::CubeMap: |
| 1200 | if (!isSubImage && width != height) |
| 1201 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1202 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1203 | return false; |
| 1204 | } |
| 1205 | |
| 1206 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 1207 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 1208 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1209 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1210 | return false; |
| 1211 | } |
| 1212 | break; |
| 1213 | |
| 1214 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1215 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1216 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 1219 | gl::Texture *texture = context->getTextureByType(texType); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1220 | if (!texture) |
| 1221 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1222 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1223 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1224 | } |
| 1225 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1226 | // Verify zero border |
| 1227 | if (border != 0) |
| 1228 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1229 | context->validationError(GL_INVALID_VALUE, kInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1230 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1233 | bool nonEqualFormatsAllowed = false; |
| 1234 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1235 | if (isCompressed) |
| 1236 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1237 | GLenum actualInternalFormat = |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1238 | isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat |
| 1239 | : internalformat; |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1240 | |
| 1241 | const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat); |
| 1242 | |
| 1243 | if (!internalFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1244 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1245 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1246 | return false; |
| 1247 | } |
| 1248 | |
| 1249 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), |
| 1250 | context->getExtensions())) |
| 1251 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1252 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1253 | return false; |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1254 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1255 | |
| 1256 | if (isSubImage) |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1257 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1258 | // From the OES_compressed_ETC1_RGB8_texture spec: |
| 1259 | // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or |
| 1260 | // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format |
| 1261 | // ETC1_RGB8_OES. |
| 1262 | if (actualInternalFormat == GL_ETC1_RGB8_OES) |
| 1263 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1264 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1265 | return false; |
| 1266 | } |
| 1267 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1268 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width, |
| 1269 | height, texture->getWidth(target, level), |
| 1270 | texture->getHeight(target, level))) |
| 1271 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1272 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1273 | return false; |
| 1274 | } |
| 1275 | |
| 1276 | if (format != actualInternalFormat) |
| 1277 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1278 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1279 | return false; |
| 1280 | } |
| 1281 | } |
| 1282 | else |
| 1283 | { |
| 1284 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 1285 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1286 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1287 | return false; |
| 1288 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | else |
| 1292 | { |
| 1293 | // validate <type> by itself (used as secondary key below) |
| 1294 | switch (type) |
| 1295 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1296 | case GL_UNSIGNED_BYTE: |
| 1297 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1298 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1299 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1300 | case GL_UNSIGNED_SHORT: |
| 1301 | case GL_UNSIGNED_INT: |
| 1302 | case GL_UNSIGNED_INT_24_8_OES: |
| 1303 | case GL_HALF_FLOAT_OES: |
| 1304 | case GL_FLOAT: |
| 1305 | break; |
| 1306 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1307 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1308 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | // validate <format> + <type> combinations |
| 1312 | // - invalid <format> -> sets INVALID_ENUM |
| 1313 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1314 | switch (format) |
| 1315 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1316 | case GL_ALPHA: |
| 1317 | case GL_LUMINANCE: |
| 1318 | case GL_LUMINANCE_ALPHA: |
| 1319 | switch (type) |
| 1320 | { |
| 1321 | case GL_UNSIGNED_BYTE: |
| 1322 | case GL_FLOAT: |
| 1323 | case GL_HALF_FLOAT_OES: |
| 1324 | break; |
| 1325 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1326 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1327 | return false; |
| 1328 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1329 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1330 | case GL_RED: |
| 1331 | case GL_RG: |
| 1332 | if (!context->getExtensions().textureRG) |
| 1333 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1334 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1335 | return false; |
| 1336 | } |
| 1337 | switch (type) |
| 1338 | { |
| 1339 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1340 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1341 | case GL_FLOAT: |
| 1342 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1343 | if (!context->getExtensions().textureFloat) |
| 1344 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1345 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1346 | return false; |
| 1347 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1348 | break; |
| 1349 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1350 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1351 | return false; |
| 1352 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1353 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1354 | case GL_RGB: |
| 1355 | switch (type) |
| 1356 | { |
| 1357 | case GL_UNSIGNED_BYTE: |
| 1358 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1359 | case GL_FLOAT: |
| 1360 | case GL_HALF_FLOAT_OES: |
| 1361 | break; |
| 1362 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1363 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1364 | return false; |
| 1365 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1366 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1367 | case GL_RGBA: |
| 1368 | switch (type) |
| 1369 | { |
| 1370 | case GL_UNSIGNED_BYTE: |
| 1371 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1372 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1373 | case GL_FLOAT: |
| 1374 | case GL_HALF_FLOAT_OES: |
| 1375 | break; |
| 1376 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1377 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1378 | return false; |
| 1379 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1380 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1381 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1382 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1383 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1384 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1385 | return false; |
| 1386 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1387 | switch (type) |
| 1388 | { |
| 1389 | case GL_UNSIGNED_BYTE: |
| 1390 | break; |
| 1391 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1392 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1393 | return false; |
| 1394 | } |
| 1395 | break; |
| 1396 | case GL_SRGB_EXT: |
| 1397 | case GL_SRGB_ALPHA_EXT: |
| 1398 | if (!context->getExtensions().sRGB) |
| 1399 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1400 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1401 | return false; |
| 1402 | } |
| 1403 | switch (type) |
| 1404 | { |
| 1405 | case GL_UNSIGNED_BYTE: |
| 1406 | break; |
| 1407 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1408 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1409 | return false; |
| 1410 | } |
| 1411 | break; |
| 1412 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1413 | // handled below |
| 1414 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1415 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1416 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1417 | break; |
| 1418 | case GL_DEPTH_COMPONENT: |
| 1419 | switch (type) |
| 1420 | { |
| 1421 | case GL_UNSIGNED_SHORT: |
| 1422 | case GL_UNSIGNED_INT: |
| 1423 | break; |
| 1424 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1425 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1426 | return false; |
| 1427 | } |
| 1428 | break; |
| 1429 | case GL_DEPTH_STENCIL_OES: |
| 1430 | switch (type) |
| 1431 | { |
| 1432 | case GL_UNSIGNED_INT_24_8_OES: |
| 1433 | break; |
| 1434 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1435 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1436 | return false; |
| 1437 | } |
| 1438 | break; |
| 1439 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1440 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1441 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | switch (format) |
| 1445 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1446 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1447 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1448 | if (context->getExtensions().textureCompressionDXT1) |
| 1449 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1450 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1451 | return false; |
| 1452 | } |
| 1453 | else |
| 1454 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1455 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1456 | return false; |
| 1457 | } |
| 1458 | break; |
| 1459 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1460 | if (context->getExtensions().textureCompressionDXT3) |
| 1461 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1462 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1463 | return false; |
| 1464 | } |
| 1465 | else |
| 1466 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1467 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1468 | return false; |
| 1469 | } |
| 1470 | break; |
| 1471 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1472 | if (context->getExtensions().textureCompressionDXT5) |
| 1473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1474 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1475 | return false; |
| 1476 | } |
| 1477 | else |
| 1478 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1479 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1480 | return false; |
| 1481 | } |
| 1482 | break; |
| 1483 | case GL_ETC1_RGB8_OES: |
| 1484 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1485 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1486 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1487 | return false; |
| 1488 | } |
| 1489 | else |
| 1490 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1491 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1492 | return false; |
| 1493 | } |
| 1494 | break; |
| 1495 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1496 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1497 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1498 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1499 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1500 | if (context->getExtensions().lossyETCDecode) |
| 1501 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1502 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1503 | return false; |
| 1504 | } |
| 1505 | else |
| 1506 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1507 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1508 | return false; |
| 1509 | } |
| 1510 | break; |
| 1511 | case GL_DEPTH_COMPONENT: |
| 1512 | case GL_DEPTH_STENCIL_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1513 | if (!context->getExtensions().depthTextureANGLE && |
| 1514 | !(context->getExtensions().packedDepthStencil && |
| 1515 | context->getExtensions().depthTextureOES)) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1516 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1517 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1518 | return false; |
| 1519 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1520 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1521 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1522 | context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1523 | return false; |
| 1524 | } |
| 1525 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1526 | // but ANGLE_depth_texture does not |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1527 | if (!context->getExtensions().depthTextureOES) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1528 | { |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1529 | if (pixels != nullptr) |
| 1530 | { |
| 1531 | context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull); |
| 1532 | return false; |
| 1533 | } |
| 1534 | if (level != 0) |
| 1535 | { |
| 1536 | context->validationError(GL_INVALID_OPERATION, kLevelNotZero); |
| 1537 | return false; |
| 1538 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1539 | } |
| 1540 | break; |
| 1541 | default: |
| 1542 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1543 | } |
| 1544 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1545 | if (!isSubImage) |
| 1546 | { |
| 1547 | switch (internalformat) |
| 1548 | { |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1549 | // Core ES 2.0 formats |
| 1550 | case GL_ALPHA: |
| 1551 | case GL_LUMINANCE: |
| 1552 | case GL_LUMINANCE_ALPHA: |
| 1553 | case GL_RGB: |
| 1554 | case GL_RGBA: |
| 1555 | break; |
| 1556 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1557 | case GL_RGBA32F: |
| 1558 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1559 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1560 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1561 | return false; |
| 1562 | } |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1563 | |
| 1564 | nonEqualFormatsAllowed = true; |
| 1565 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1566 | if (type != GL_FLOAT) |
| 1567 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1568 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1569 | return false; |
| 1570 | } |
| 1571 | if (format != GL_RGBA) |
| 1572 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1573 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1574 | return false; |
| 1575 | } |
| 1576 | break; |
| 1577 | |
| 1578 | case GL_RGB32F: |
| 1579 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1580 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1581 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1582 | return false; |
| 1583 | } |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1584 | |
| 1585 | nonEqualFormatsAllowed = true; |
| 1586 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1587 | if (type != GL_FLOAT) |
| 1588 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1589 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1590 | return false; |
| 1591 | } |
| 1592 | if (format != GL_RGB) |
| 1593 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1594 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1595 | return false; |
| 1596 | } |
| 1597 | break; |
| 1598 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1599 | case GL_BGRA_EXT: |
| 1600 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1601 | { |
| 1602 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1603 | return false; |
| 1604 | } |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1605 | break; |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1606 | |
| 1607 | case GL_DEPTH_COMPONENT: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1608 | if (!(context->getExtensions().depthTextureAny())) |
| 1609 | { |
| 1610 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1611 | return false; |
| 1612 | } |
| 1613 | break; |
| 1614 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1615 | case GL_DEPTH_STENCIL: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1616 | if (!(context->getExtensions().depthTextureANGLE || |
| 1617 | context->getExtensions().packedDepthStencil)) |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1618 | { |
| 1619 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1620 | return false; |
| 1621 | } |
| 1622 | break; |
| 1623 | |
| 1624 | case GL_RED: |
| 1625 | case GL_RG: |
| 1626 | if (!context->getExtensions().textureRG) |
| 1627 | { |
| 1628 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
| 1629 | return false; |
| 1630 | } |
| 1631 | break; |
| 1632 | |
| 1633 | case GL_SRGB_EXT: |
| 1634 | case GL_SRGB_ALPHA_EXT: |
| 1635 | if (!context->getExtensions().sRGB) |
| 1636 | { |
| 1637 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1638 | return false; |
| 1639 | } |
| 1640 | break; |
| 1641 | |
| 1642 | default: |
| 1643 | context->validationError(GL_INVALID_VALUE, kInvalidInternalFormat); |
| 1644 | return false; |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1648 | if (type == GL_FLOAT) |
| 1649 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1650 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1651 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1652 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1653 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1654 | } |
| 1655 | } |
| 1656 | else if (type == GL_HALF_FLOAT_OES) |
| 1657 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1658 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1659 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1660 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1661 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1666 | if (isSubImage) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1667 | { |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1668 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 1669 | if (textureInternalFormat.internalFormat == GL_NONE) |
| 1670 | { |
| 1671 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel); |
| 1672 | return false; |
| 1673 | } |
| 1674 | |
Tim Van Patten | 5f388c2 | 2019-03-14 09:54:23 -0600 | [diff] [blame] | 1675 | if (format != textureInternalFormat.format) |
| 1676 | { |
| 1677 | context->validationError(GL_INVALID_OPERATION, err::kTextureFormatMismatch); |
| 1678 | return false; |
| 1679 | } |
| 1680 | |
| 1681 | if (context->getExtensions().webglCompatibility) |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1682 | { |
| 1683 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 1684 | textureInternalFormat.sizedInternalFormat) |
| 1685 | { |
Tim Van Patten | 5f388c2 | 2019-03-14 09:54:23 -0600 | [diff] [blame] | 1686 | context->validationError(GL_INVALID_OPERATION, kTextureTypeMismatch); |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1687 | return false; |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1692 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 1693 | { |
| 1694 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
| 1695 | return false; |
| 1696 | } |
| 1697 | |
| 1698 | if (width > 0 && height > 0 && pixels == nullptr && |
| 1699 | context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr) |
| 1700 | { |
| 1701 | context->validationError(GL_INVALID_VALUE, kPixelDataNull); |
| 1702 | return false; |
| 1703 | } |
| 1704 | } |
| 1705 | else |
| 1706 | { |
| 1707 | if (texture->getImmutableFormat()) |
| 1708 | { |
| 1709 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
| 1710 | return false; |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 1715 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 1716 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 1717 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 1718 | // case. |
| 1719 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
| 1720 | { |
| 1721 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1722 | return false; |
| 1723 | } |
| 1724 | |
Tim Van Patten | 208af3e | 2019-03-19 09:15:55 -0600 | [diff] [blame] | 1725 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
| 1726 | return ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
| 1727 | imageSize); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1728 | } |
| 1729 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1730 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1731 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1732 | GLsizei levels, |
| 1733 | GLenum internalformat, |
| 1734 | GLsizei width, |
| 1735 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1736 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1737 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1738 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1739 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1740 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1741 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | if (width < 1 || height < 1 || levels < 1) |
| 1745 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1746 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1747 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1748 | } |
| 1749 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1750 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1751 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1752 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1753 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1757 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1758 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1759 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1760 | } |
| 1761 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1762 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1763 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1764 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1765 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1766 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1767 | } |
| 1768 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1769 | const gl::Caps &caps = context->getCaps(); |
| 1770 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1771 | switch (target) |
| 1772 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1773 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1774 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1775 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1776 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1777 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1778 | return false; |
| 1779 | } |
| 1780 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1781 | case TextureType::Rectangle: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1782 | if (levels != 1) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1783 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1784 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1785 | return false; |
| 1786 | } |
| 1787 | |
| 1788 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1789 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1790 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1791 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1792 | return false; |
| 1793 | } |
| 1794 | if (formatInfo.compressed) |
| 1795 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1796 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1797 | return false; |
| 1798 | } |
| 1799 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1800 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1801 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1802 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1803 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1804 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1805 | return false; |
| 1806 | } |
| 1807 | break; |
| 1808 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1809 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1810 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1811 | } |
| 1812 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1813 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1814 | { |
| 1815 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1816 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1817 | context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1818 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | switch (internalformat) |
| 1823 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1824 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1825 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1826 | if (!context->getExtensions().textureCompressionDXT1) |
| 1827 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1828 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1829 | return false; |
| 1830 | } |
| 1831 | break; |
| 1832 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1833 | if (!context->getExtensions().textureCompressionDXT3) |
| 1834 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1835 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1836 | return false; |
| 1837 | } |
| 1838 | break; |
| 1839 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1840 | if (!context->getExtensions().textureCompressionDXT5) |
| 1841 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1842 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1843 | return false; |
| 1844 | } |
| 1845 | break; |
| 1846 | case GL_ETC1_RGB8_OES: |
| 1847 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1848 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1849 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1850 | return false; |
| 1851 | } |
| 1852 | break; |
| 1853 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1854 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1855 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1856 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1857 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1858 | if (!context->getExtensions().lossyETCDecode) |
| 1859 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1860 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1861 | return false; |
| 1862 | } |
| 1863 | break; |
| 1864 | case GL_RGBA32F_EXT: |
| 1865 | case GL_RGB32F_EXT: |
| 1866 | case GL_ALPHA32F_EXT: |
| 1867 | case GL_LUMINANCE32F_EXT: |
| 1868 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1869 | if (!context->getExtensions().textureFloat) |
| 1870 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1871 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1872 | return false; |
| 1873 | } |
| 1874 | break; |
| 1875 | case GL_RGBA16F_EXT: |
| 1876 | case GL_RGB16F_EXT: |
| 1877 | case GL_ALPHA16F_EXT: |
| 1878 | case GL_LUMINANCE16F_EXT: |
| 1879 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1880 | if (!context->getExtensions().textureHalfFloat) |
| 1881 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1882 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1883 | return false; |
| 1884 | } |
| 1885 | break; |
| 1886 | case GL_R8_EXT: |
| 1887 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1888 | if (!context->getExtensions().textureRG) |
| 1889 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1890 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1891 | return false; |
| 1892 | } |
| 1893 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1894 | case GL_R16F_EXT: |
| 1895 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1896 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1897 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1898 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1899 | return false; |
| 1900 | } |
| 1901 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1902 | case GL_R32F_EXT: |
| 1903 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1904 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1905 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1906 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1907 | return false; |
| 1908 | } |
| 1909 | break; |
| 1910 | case GL_DEPTH_COMPONENT16: |
| 1911 | case GL_DEPTH_COMPONENT32_OES: |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1912 | if (!(context->getExtensions().depthTextureAny())) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1913 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1914 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1915 | return false; |
| 1916 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1917 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1918 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1919 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1920 | return false; |
| 1921 | } |
| 1922 | // ANGLE_depth_texture only supports 1-level textures |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1923 | if (!context->getExtensions().depthTextureOES) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1924 | { |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1925 | if (levels != 1) |
| 1926 | { |
| 1927 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
| 1928 | return false; |
| 1929 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1930 | } |
| 1931 | break; |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame] | 1932 | case GL_DEPTH24_STENCIL8_OES: |
| 1933 | if (!(context->getExtensions().depthTextureANGLE || |
| 1934 | (context->getExtensions().packedDepthStencil && |
| 1935 | context->getExtensions().textureStorage))) |
| 1936 | { |
| 1937 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 1938 | return false; |
| 1939 | } |
| 1940 | if (target != TextureType::_2D) |
| 1941 | { |
| 1942 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
| 1943 | return false; |
| 1944 | } |
| 1945 | if (!context->getExtensions().packedDepthStencil) |
| 1946 | { |
| 1947 | // ANGLE_depth_texture only supports 1-level textures |
| 1948 | if (levels != 1) |
| 1949 | { |
| 1950 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
| 1951 | return false; |
| 1952 | } |
| 1953 | } |
| 1954 | break; |
| 1955 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1956 | default: |
| 1957 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1958 | } |
| 1959 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 1960 | gl::Texture *texture = context->getTextureByType(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1961 | if (!texture || texture->id() == 0) |
| 1962 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1963 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1964 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1967 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1968 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1969 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1970 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | return true; |
| 1974 | } |
| 1975 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1976 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 1977 | GLenum target, |
| 1978 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1979 | const GLenum *attachments) |
| 1980 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1981 | if (!context->getExtensions().discardFramebuffer) |
| 1982 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1983 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1984 | return false; |
| 1985 | } |
| 1986 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1987 | bool defaultFramebuffer = false; |
| 1988 | |
| 1989 | switch (target) |
| 1990 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1991 | case GL_FRAMEBUFFER: |
| 1992 | defaultFramebuffer = |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1993 | (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1994 | break; |
| 1995 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1996 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1997 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2000 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 2001 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2004 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 2005 | { |
| 2006 | if (!context->getExtensions().vertexArrayObject) |
| 2007 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2008 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
| 2011 | |
| 2012 | return ValidateBindVertexArrayBase(context, array); |
| 2013 | } |
| 2014 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 2015 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2016 | { |
| 2017 | if (!context->getExtensions().vertexArrayObject) |
| 2018 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2019 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2020 | return false; |
| 2021 | } |
| 2022 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2023 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 2026 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2027 | { |
| 2028 | if (!context->getExtensions().vertexArrayObject) |
| 2029 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2030 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2031 | return false; |
| 2032 | } |
| 2033 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2034 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 2037 | bool ValidateIsVertexArrayOES(Context *context, GLuint array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2038 | { |
| 2039 | if (!context->getExtensions().vertexArrayObject) |
| 2040 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2041 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2042 | return false; |
| 2043 | } |
| 2044 | |
| 2045 | return true; |
| 2046 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2047 | |
| 2048 | bool ValidateProgramBinaryOES(Context *context, |
| 2049 | GLuint program, |
| 2050 | GLenum binaryFormat, |
| 2051 | const void *binary, |
| 2052 | GLint length) |
| 2053 | { |
| 2054 | if (!context->getExtensions().getProgramBinary) |
| 2055 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2056 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2057 | return false; |
| 2058 | } |
| 2059 | |
| 2060 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 2061 | } |
| 2062 | |
| 2063 | bool ValidateGetProgramBinaryOES(Context *context, |
| 2064 | GLuint program, |
| 2065 | GLsizei bufSize, |
| 2066 | GLsizei *length, |
| 2067 | GLenum *binaryFormat, |
| 2068 | void *binary) |
| 2069 | { |
| 2070 | if (!context->getExtensions().getProgramBinary) |
| 2071 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2072 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2073 | return false; |
| 2074 | } |
| 2075 | |
| 2076 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 2077 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2078 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2079 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 2080 | { |
| 2081 | switch (source) |
| 2082 | { |
| 2083 | case GL_DEBUG_SOURCE_API: |
| 2084 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 2085 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 2086 | case GL_DEBUG_SOURCE_OTHER: |
| 2087 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 2088 | return !mustBeThirdPartyOrApplication; |
| 2089 | |
| 2090 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 2091 | case GL_DEBUG_SOURCE_APPLICATION: |
| 2092 | return true; |
| 2093 | |
| 2094 | default: |
| 2095 | return false; |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | static bool ValidDebugType(GLenum type) |
| 2100 | { |
| 2101 | switch (type) |
| 2102 | { |
| 2103 | case GL_DEBUG_TYPE_ERROR: |
| 2104 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 2105 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 2106 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 2107 | case GL_DEBUG_TYPE_PORTABILITY: |
| 2108 | case GL_DEBUG_TYPE_OTHER: |
| 2109 | case GL_DEBUG_TYPE_MARKER: |
| 2110 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 2111 | case GL_DEBUG_TYPE_POP_GROUP: |
| 2112 | return true; |
| 2113 | |
| 2114 | default: |
| 2115 | return false; |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | static bool ValidDebugSeverity(GLenum severity) |
| 2120 | { |
| 2121 | switch (severity) |
| 2122 | { |
| 2123 | case GL_DEBUG_SEVERITY_HIGH: |
| 2124 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 2125 | case GL_DEBUG_SEVERITY_LOW: |
| 2126 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 2127 | return true; |
| 2128 | |
| 2129 | default: |
| 2130 | return false; |
| 2131 | } |
| 2132 | } |
| 2133 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2134 | bool ValidateDebugMessageControlKHR(Context *context, |
| 2135 | GLenum source, |
| 2136 | GLenum type, |
| 2137 | GLenum severity, |
| 2138 | GLsizei count, |
| 2139 | const GLuint *ids, |
| 2140 | GLboolean enabled) |
| 2141 | { |
| 2142 | if (!context->getExtensions().debug) |
| 2143 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2144 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2145 | return false; |
| 2146 | } |
| 2147 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2148 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 2149 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2150 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2151 | return false; |
| 2152 | } |
| 2153 | |
| 2154 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 2155 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2156 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2157 | return false; |
| 2158 | } |
| 2159 | |
| 2160 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 2161 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2162 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2163 | return false; |
| 2164 | } |
| 2165 | |
| 2166 | if (count > 0) |
| 2167 | { |
| 2168 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2169 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2170 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2171 | return false; |
| 2172 | } |
| 2173 | |
| 2174 | if (severity != GL_DONT_CARE) |
| 2175 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2176 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2177 | return false; |
| 2178 | } |
| 2179 | } |
| 2180 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2181 | return true; |
| 2182 | } |
| 2183 | |
| 2184 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2185 | GLenum source, |
| 2186 | GLenum type, |
| 2187 | GLuint id, |
| 2188 | GLenum severity, |
| 2189 | GLsizei length, |
| 2190 | const GLchar *buf) |
| 2191 | { |
| 2192 | if (!context->getExtensions().debug) |
| 2193 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2194 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2195 | return false; |
| 2196 | } |
| 2197 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2198 | if (!context->getState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2199 | { |
| 2200 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2201 | // not generate an error. |
| 2202 | return false; |
| 2203 | } |
| 2204 | |
| 2205 | if (!ValidDebugSeverity(severity)) |
| 2206 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2207 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2208 | return false; |
| 2209 | } |
| 2210 | |
| 2211 | if (!ValidDebugType(type)) |
| 2212 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2213 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2214 | return false; |
| 2215 | } |
| 2216 | |
| 2217 | if (!ValidDebugSource(source, true)) |
| 2218 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2219 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2220 | return false; |
| 2221 | } |
| 2222 | |
| 2223 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2224 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2225 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2226 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2227 | return false; |
| 2228 | } |
| 2229 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2230 | return true; |
| 2231 | } |
| 2232 | |
| 2233 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2234 | GLDEBUGPROCKHR callback, |
| 2235 | const void *userParam) |
| 2236 | { |
| 2237 | if (!context->getExtensions().debug) |
| 2238 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2239 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2240 | return false; |
| 2241 | } |
| 2242 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2243 | return true; |
| 2244 | } |
| 2245 | |
| 2246 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2247 | GLuint count, |
| 2248 | GLsizei bufSize, |
| 2249 | GLenum *sources, |
| 2250 | GLenum *types, |
| 2251 | GLuint *ids, |
| 2252 | GLenum *severities, |
| 2253 | GLsizei *lengths, |
| 2254 | GLchar *messageLog) |
| 2255 | { |
| 2256 | if (!context->getExtensions().debug) |
| 2257 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2258 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2259 | return false; |
| 2260 | } |
| 2261 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2262 | if (bufSize < 0 && messageLog != nullptr) |
| 2263 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2264 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2265 | return false; |
| 2266 | } |
| 2267 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2268 | return true; |
| 2269 | } |
| 2270 | |
| 2271 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2272 | GLenum source, |
| 2273 | GLuint id, |
| 2274 | GLsizei length, |
| 2275 | const GLchar *message) |
| 2276 | { |
| 2277 | if (!context->getExtensions().debug) |
| 2278 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2279 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2280 | return false; |
| 2281 | } |
| 2282 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2283 | if (!ValidDebugSource(source, true)) |
| 2284 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2285 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2286 | return false; |
| 2287 | } |
| 2288 | |
| 2289 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2290 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2291 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2292 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2293 | return false; |
| 2294 | } |
| 2295 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2296 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2297 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2298 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2299 | context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2300 | return false; |
| 2301 | } |
| 2302 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2303 | return true; |
| 2304 | } |
| 2305 | |
| 2306 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2307 | { |
| 2308 | if (!context->getExtensions().debug) |
| 2309 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2310 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2311 | return false; |
| 2312 | } |
| 2313 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2314 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2315 | if (currentStackSize <= 1) |
| 2316 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2317 | context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2318 | return false; |
| 2319 | } |
| 2320 | |
| 2321 | return true; |
| 2322 | } |
| 2323 | |
| 2324 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2325 | { |
| 2326 | switch (identifier) |
| 2327 | { |
| 2328 | case GL_BUFFER: |
| 2329 | if (context->getBuffer(name) == nullptr) |
| 2330 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2331 | context->validationError(GL_INVALID_VALUE, kInvalidBufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2332 | return false; |
| 2333 | } |
| 2334 | return true; |
| 2335 | |
| 2336 | case GL_SHADER: |
| 2337 | if (context->getShader(name) == nullptr) |
| 2338 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2339 | context->validationError(GL_INVALID_VALUE, kInvalidShaderName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2340 | return false; |
| 2341 | } |
| 2342 | return true; |
| 2343 | |
| 2344 | case GL_PROGRAM: |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2345 | if (context->getProgramNoResolveLink(name) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2346 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2347 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2348 | return false; |
| 2349 | } |
| 2350 | return true; |
| 2351 | |
| 2352 | case GL_VERTEX_ARRAY: |
| 2353 | if (context->getVertexArray(name) == nullptr) |
| 2354 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2355 | context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2356 | return false; |
| 2357 | } |
| 2358 | return true; |
| 2359 | |
| 2360 | case GL_QUERY: |
| 2361 | if (context->getQuery(name) == nullptr) |
| 2362 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2363 | context->validationError(GL_INVALID_VALUE, kInvalidQueryName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2364 | return false; |
| 2365 | } |
| 2366 | return true; |
| 2367 | |
| 2368 | case GL_TRANSFORM_FEEDBACK: |
| 2369 | if (context->getTransformFeedback(name) == nullptr) |
| 2370 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2371 | context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2372 | return false; |
| 2373 | } |
| 2374 | return true; |
| 2375 | |
| 2376 | case GL_SAMPLER: |
| 2377 | if (context->getSampler(name) == nullptr) |
| 2378 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2379 | context->validationError(GL_INVALID_VALUE, kInvalidSamplerName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2380 | return false; |
| 2381 | } |
| 2382 | return true; |
| 2383 | |
| 2384 | case GL_TEXTURE: |
| 2385 | if (context->getTexture(name) == nullptr) |
| 2386 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2387 | context->validationError(GL_INVALID_VALUE, kInvalidTextureName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2388 | return false; |
| 2389 | } |
| 2390 | return true; |
| 2391 | |
| 2392 | case GL_RENDERBUFFER: |
| 2393 | if (context->getRenderbuffer(name) == nullptr) |
| 2394 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2395 | context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2396 | return false; |
| 2397 | } |
| 2398 | return true; |
| 2399 | |
| 2400 | case GL_FRAMEBUFFER: |
| 2401 | if (context->getFramebuffer(name) == nullptr) |
| 2402 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2403 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2404 | return false; |
| 2405 | } |
| 2406 | return true; |
| 2407 | |
| 2408 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2409 | context->validationError(GL_INVALID_ENUM, kInvalidIndentifier); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2410 | return false; |
| 2411 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2412 | } |
| 2413 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2414 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2415 | { |
| 2416 | size_t labelLength = 0; |
| 2417 | |
| 2418 | if (length < 0) |
| 2419 | { |
| 2420 | if (label != nullptr) |
| 2421 | { |
| 2422 | labelLength = strlen(label); |
| 2423 | } |
| 2424 | } |
| 2425 | else |
| 2426 | { |
| 2427 | labelLength = static_cast<size_t>(length); |
| 2428 | } |
| 2429 | |
| 2430 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2431 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2432 | context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2433 | return false; |
| 2434 | } |
| 2435 | |
| 2436 | return true; |
| 2437 | } |
| 2438 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2439 | bool ValidateObjectLabelKHR(Context *context, |
| 2440 | GLenum identifier, |
| 2441 | GLuint name, |
| 2442 | GLsizei length, |
| 2443 | const GLchar *label) |
| 2444 | { |
| 2445 | if (!context->getExtensions().debug) |
| 2446 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2447 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2448 | return false; |
| 2449 | } |
| 2450 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2451 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2452 | { |
| 2453 | return false; |
| 2454 | } |
| 2455 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2456 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2457 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2458 | return false; |
| 2459 | } |
| 2460 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2461 | return true; |
| 2462 | } |
| 2463 | |
| 2464 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2465 | GLenum identifier, |
| 2466 | GLuint name, |
| 2467 | GLsizei bufSize, |
| 2468 | GLsizei *length, |
| 2469 | GLchar *label) |
| 2470 | { |
| 2471 | if (!context->getExtensions().debug) |
| 2472 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2473 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2474 | return false; |
| 2475 | } |
| 2476 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2477 | if (bufSize < 0) |
| 2478 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2479 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2480 | return false; |
| 2481 | } |
| 2482 | |
| 2483 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2484 | { |
| 2485 | return false; |
| 2486 | } |
| 2487 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2488 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2492 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2493 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2494 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2495 | context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2496 | return false; |
| 2497 | } |
| 2498 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2499 | return true; |
| 2500 | } |
| 2501 | |
| 2502 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2503 | const void *ptr, |
| 2504 | GLsizei length, |
| 2505 | const GLchar *label) |
| 2506 | { |
| 2507 | if (!context->getExtensions().debug) |
| 2508 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2509 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2510 | return false; |
| 2511 | } |
| 2512 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2513 | if (!ValidateObjectPtrName(context, ptr)) |
| 2514 | { |
| 2515 | return false; |
| 2516 | } |
| 2517 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2518 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2519 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2520 | return false; |
| 2521 | } |
| 2522 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2523 | return true; |
| 2524 | } |
| 2525 | |
| 2526 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2527 | const void *ptr, |
| 2528 | GLsizei bufSize, |
| 2529 | GLsizei *length, |
| 2530 | GLchar *label) |
| 2531 | { |
| 2532 | if (!context->getExtensions().debug) |
| 2533 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2534 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2535 | return false; |
| 2536 | } |
| 2537 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2538 | if (bufSize < 0) |
| 2539 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2540 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2541 | return false; |
| 2542 | } |
| 2543 | |
| 2544 | if (!ValidateObjectPtrName(context, ptr)) |
| 2545 | { |
| 2546 | return false; |
| 2547 | } |
| 2548 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2549 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2553 | { |
| 2554 | if (!context->getExtensions().debug) |
| 2555 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2556 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2557 | return false; |
| 2558 | } |
| 2559 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2560 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2561 | switch (pname) |
| 2562 | { |
| 2563 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2564 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2565 | break; |
| 2566 | |
| 2567 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2568 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2569 | return false; |
| 2570 | } |
| 2571 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2572 | return true; |
| 2573 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2574 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2575 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2576 | GLenum pname, |
| 2577 | GLsizei bufSize, |
| 2578 | GLsizei *length, |
| 2579 | void **params) |
| 2580 | { |
| 2581 | UNIMPLEMENTED(); |
| 2582 | return false; |
| 2583 | } |
| 2584 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2585 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2586 | GLint srcX0, |
| 2587 | GLint srcY0, |
| 2588 | GLint srcX1, |
| 2589 | GLint srcY1, |
| 2590 | GLint dstX0, |
| 2591 | GLint dstY0, |
| 2592 | GLint dstX1, |
| 2593 | GLint dstY1, |
| 2594 | GLbitfield mask, |
| 2595 | GLenum filter) |
| 2596 | { |
| 2597 | if (!context->getExtensions().framebufferBlit) |
| 2598 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2599 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2600 | return false; |
| 2601 | } |
| 2602 | |
| 2603 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2604 | { |
| 2605 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2606 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2607 | return false; |
| 2608 | } |
| 2609 | |
| 2610 | if (filter == GL_LINEAR) |
| 2611 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2612 | context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2613 | return false; |
| 2614 | } |
| 2615 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2616 | Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 2617 | Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2618 | |
| 2619 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2620 | { |
| 2621 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 2622 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 2623 | |
| 2624 | if (readColorAttachment && drawColorAttachment) |
| 2625 | { |
| 2626 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2627 | readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2628 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2629 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2630 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2631 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2632 | kBlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2633 | return false; |
| 2634 | } |
| 2635 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2636 | for (size_t drawbufferIdx = 0; |
| 2637 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2638 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2639 | const FramebufferAttachment *attachment = |
| 2640 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2641 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2642 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2643 | if (!(attachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2644 | attachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2645 | attachment->type() != GL_RENDERBUFFER && |
| 2646 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2647 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2648 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2649 | kBlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2650 | return false; |
| 2651 | } |
| 2652 | |
| 2653 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2654 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2655 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2656 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2657 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2658 | kBlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2659 | return false; |
| 2660 | } |
| 2661 | } |
| 2662 | } |
| 2663 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2664 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2665 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2666 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2667 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2668 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2669 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2670 | kBlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2671 | return false; |
| 2672 | } |
| 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2677 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2678 | for (size_t i = 0; i < 2; i++) |
| 2679 | { |
| 2680 | if (mask & masks[i]) |
| 2681 | { |
| 2682 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2683 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2684 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2685 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2686 | |
| 2687 | if (readBuffer && drawBuffer) |
| 2688 | { |
| 2689 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2690 | dstX0, dstY0, dstX1, dstY1)) |
| 2691 | { |
| 2692 | // only whole-buffer copies are permitted |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2693 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2694 | kBlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2695 | return false; |
| 2696 | } |
| 2697 | |
| 2698 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2699 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2700 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2701 | kBlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2702 | return false; |
| 2703 | } |
| 2704 | } |
| 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2709 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2710 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2711 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2712 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2713 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2714 | Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2715 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2716 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2717 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2718 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2719 | return false; |
| 2720 | } |
| 2721 | |
| 2722 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2723 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2724 | context->validationError(GL_INVALID_VALUE, kInvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2725 | return false; |
| 2726 | } |
| 2727 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2728 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2729 | { |
| 2730 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2731 | GL_SIGNED_NORMALIZED}; |
| 2732 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2733 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2734 | drawBufferIdx++) |
| 2735 | { |
| 2736 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2737 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2738 | { |
| 2739 | return false; |
| 2740 | } |
| 2741 | } |
| 2742 | } |
| 2743 | |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame] | 2744 | if ((extensions.multiview || extensions.multiview2) && extensions.disjointTimerQuery) |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2745 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2746 | const State &state = context->getState(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2747 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2748 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2749 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2750 | context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2751 | return false; |
| 2752 | } |
| 2753 | } |
| 2754 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2755 | return true; |
| 2756 | } |
| 2757 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2758 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2759 | { |
| 2760 | if (!context->getExtensions().drawBuffers) |
| 2761 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2762 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2763 | return false; |
| 2764 | } |
| 2765 | |
| 2766 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2767 | } |
| 2768 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2769 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2770 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2771 | GLint level, |
| 2772 | GLint internalformat, |
| 2773 | GLsizei width, |
| 2774 | GLsizei height, |
| 2775 | GLint border, |
| 2776 | GLenum format, |
| 2777 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2778 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2779 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2780 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2781 | { |
| 2782 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2783 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2784 | } |
| 2785 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2786 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2787 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2788 | 0, 0, width, height, 1, border, format, type, -1, |
| 2789 | pixels); |
| 2790 | } |
| 2791 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2792 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2793 | TextureTarget target, |
| 2794 | GLint level, |
| 2795 | GLint internalformat, |
| 2796 | GLsizei width, |
| 2797 | GLsizei height, |
| 2798 | GLint border, |
| 2799 | GLenum format, |
| 2800 | GLenum type, |
| 2801 | GLsizei bufSize, |
| 2802 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2803 | { |
| 2804 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2805 | { |
| 2806 | return false; |
| 2807 | } |
| 2808 | |
| 2809 | if (context->getClientMajorVersion() < 3) |
| 2810 | { |
| 2811 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2812 | 0, 0, width, height, border, format, type, bufSize, |
| 2813 | pixels); |
| 2814 | } |
| 2815 | |
| 2816 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2817 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2818 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2819 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2823 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2824 | GLint level, |
| 2825 | GLint xoffset, |
| 2826 | GLint yoffset, |
| 2827 | GLsizei width, |
| 2828 | GLsizei height, |
| 2829 | GLenum format, |
| 2830 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2831 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2832 | { |
| 2833 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2834 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2835 | { |
| 2836 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2837 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2838 | } |
| 2839 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2840 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2841 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2842 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2843 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2844 | } |
| 2845 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2846 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2847 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2848 | GLint level, |
| 2849 | GLint xoffset, |
| 2850 | GLint yoffset, |
| 2851 | GLsizei width, |
| 2852 | GLsizei height, |
| 2853 | GLenum format, |
| 2854 | GLenum type, |
| 2855 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2856 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2857 | { |
| 2858 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2859 | { |
| 2860 | return false; |
| 2861 | } |
| 2862 | |
| 2863 | if (context->getClientMajorVersion() < 3) |
| 2864 | { |
| 2865 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2866 | yoffset, width, height, 0, format, type, bufSize, |
| 2867 | pixels); |
| 2868 | } |
| 2869 | |
| 2870 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2871 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2872 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2873 | pixels); |
| 2874 | } |
| 2875 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2876 | bool ValidateCompressedTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2877 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2878 | GLint level, |
| 2879 | GLenum internalformat, |
| 2880 | GLsizei width, |
| 2881 | GLsizei height, |
| 2882 | GLint border, |
| 2883 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2884 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2885 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2886 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2887 | { |
| 2888 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2889 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2890 | { |
| 2891 | return false; |
| 2892 | } |
| 2893 | } |
| 2894 | else |
| 2895 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2896 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2897 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2898 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2899 | data)) |
| 2900 | { |
| 2901 | return false; |
| 2902 | } |
| 2903 | } |
| 2904 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2905 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2906 | |
| 2907 | GLuint blockSize = 0; |
| 2908 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2909 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2910 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2911 | return false; |
| 2912 | } |
| 2913 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2914 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2915 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2916 | context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2917 | return false; |
| 2918 | } |
| 2919 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2920 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2921 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2922 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2923 | return false; |
| 2924 | } |
| 2925 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2926 | return true; |
| 2927 | } |
| 2928 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2929 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2930 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2931 | GLint level, |
| 2932 | GLenum internalformat, |
| 2933 | GLsizei width, |
| 2934 | GLsizei height, |
| 2935 | GLint border, |
| 2936 | GLsizei imageSize, |
| 2937 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2938 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2939 | { |
| 2940 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2941 | { |
| 2942 | return false; |
| 2943 | } |
| 2944 | |
| 2945 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 2946 | border, imageSize, data); |
| 2947 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2948 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2949 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2950 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2951 | GLint level, |
| 2952 | GLint xoffset, |
| 2953 | GLint yoffset, |
| 2954 | GLsizei width, |
| 2955 | GLsizei height, |
| 2956 | GLenum format, |
| 2957 | GLsizei imageSize, |
| 2958 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2959 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2960 | { |
| 2961 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2962 | { |
| 2963 | return false; |
| 2964 | } |
| 2965 | |
| 2966 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 2967 | format, imageSize, data); |
| 2968 | } |
| 2969 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2970 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2971 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2972 | GLint level, |
| 2973 | GLint xoffset, |
| 2974 | GLint yoffset, |
| 2975 | GLsizei width, |
| 2976 | GLsizei height, |
| 2977 | GLenum format, |
| 2978 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2979 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2980 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2981 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2982 | { |
| 2983 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2984 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2985 | { |
| 2986 | return false; |
| 2987 | } |
| 2988 | } |
| 2989 | else |
| 2990 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2991 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2992 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2993 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2994 | data)) |
| 2995 | { |
| 2996 | return false; |
| 2997 | } |
| 2998 | } |
| 2999 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3000 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3001 | GLuint blockSize = 0; |
| 3002 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3003 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3004 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3005 | return false; |
| 3006 | } |
| 3007 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 3008 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3009 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3010 | context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3011 | return false; |
| 3012 | } |
| 3013 | |
| 3014 | return true; |
| 3015 | } |
| 3016 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3017 | bool ValidateGetBufferPointervOES(Context *context, |
| 3018 | BufferBinding target, |
| 3019 | GLenum pname, |
| 3020 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3021 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3022 | if (!context->getExtensions().mapBuffer) |
| 3023 | { |
| 3024 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3025 | return false; |
| 3026 | } |
| 3027 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3028 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3029 | } |
| 3030 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3031 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3032 | { |
| 3033 | if (!context->getExtensions().mapBuffer) |
| 3034 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3035 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3036 | return false; |
| 3037 | } |
| 3038 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3039 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3040 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3041 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3042 | return false; |
| 3043 | } |
| 3044 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3045 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3046 | |
| 3047 | if (buffer == nullptr) |
| 3048 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3049 | context->validationError(GL_INVALID_OPERATION, kBufferNotMappable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3050 | return false; |
| 3051 | } |
| 3052 | |
| 3053 | if (access != GL_WRITE_ONLY_OES) |
| 3054 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3055 | context->validationError(GL_INVALID_ENUM, kInvalidAccessBits); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3056 | return false; |
| 3057 | } |
| 3058 | |
| 3059 | if (buffer->isMapped()) |
| 3060 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3061 | context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3062 | return false; |
| 3063 | } |
| 3064 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3065 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3066 | } |
| 3067 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3068 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3069 | { |
| 3070 | if (!context->getExtensions().mapBuffer) |
| 3071 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3072 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3073 | return false; |
| 3074 | } |
| 3075 | |
| 3076 | return ValidateUnmapBufferBase(context, target); |
| 3077 | } |
| 3078 | |
| 3079 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3080 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3081 | GLintptr offset, |
| 3082 | GLsizeiptr length, |
| 3083 | GLbitfield access) |
| 3084 | { |
| 3085 | if (!context->getExtensions().mapBufferRange) |
| 3086 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3087 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3088 | return false; |
| 3089 | } |
| 3090 | |
| 3091 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 3092 | } |
| 3093 | |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3094 | bool ValidateBufferStorageMemEXT(Context *context, |
| 3095 | TextureType target, |
| 3096 | GLsizeiptr size, |
| 3097 | GLuint memory, |
| 3098 | GLuint64 offset) |
| 3099 | { |
| 3100 | if (!context->getExtensions().memoryObject) |
| 3101 | { |
| 3102 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3103 | return false; |
| 3104 | } |
| 3105 | |
| 3106 | UNIMPLEMENTED(); |
| 3107 | return false; |
| 3108 | } |
| 3109 | |
| 3110 | bool ValidateCreateMemoryObjectsEXT(Context *context, GLsizei n, GLuint *memoryObjects) |
| 3111 | { |
| 3112 | if (!context->getExtensions().memoryObject) |
| 3113 | { |
| 3114 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3115 | return false; |
| 3116 | } |
| 3117 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3118 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | bool ValidateDeleteMemoryObjectsEXT(Context *context, GLsizei n, const GLuint *memoryObjects) |
| 3122 | { |
| 3123 | if (!context->getExtensions().memoryObject) |
| 3124 | { |
| 3125 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3126 | return false; |
| 3127 | } |
| 3128 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3129 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | bool ValidateGetMemoryObjectParameterivEXT(Context *context, |
| 3133 | GLuint memoryObject, |
| 3134 | GLenum pname, |
| 3135 | GLint *params) |
| 3136 | { |
| 3137 | if (!context->getExtensions().memoryObject) |
| 3138 | { |
| 3139 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3140 | return false; |
| 3141 | } |
| 3142 | |
| 3143 | UNIMPLEMENTED(); |
| 3144 | return false; |
| 3145 | } |
| 3146 | |
| 3147 | bool ValidateGetUnsignedBytevEXT(Context *context, GLenum pname, GLubyte *data) |
| 3148 | { |
| 3149 | if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore) |
| 3150 | { |
| 3151 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3152 | return false; |
| 3153 | } |
| 3154 | |
| 3155 | UNIMPLEMENTED(); |
| 3156 | return false; |
| 3157 | } |
| 3158 | |
| 3159 | bool ValidateGetUnsignedBytei_vEXT(Context *context, GLenum target, GLuint index, GLubyte *data) |
| 3160 | { |
| 3161 | if (!context->getExtensions().memoryObject && !context->getExtensions().semaphore) |
| 3162 | { |
| 3163 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3164 | return false; |
| 3165 | } |
| 3166 | |
| 3167 | UNIMPLEMENTED(); |
| 3168 | return false; |
| 3169 | } |
| 3170 | |
| 3171 | bool ValidateIsMemoryObjectEXT(Context *context, GLuint memoryObject) |
| 3172 | { |
| 3173 | if (!context->getExtensions().memoryObject) |
| 3174 | { |
| 3175 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3176 | return false; |
| 3177 | } |
| 3178 | |
Michael Spang | fb201c5 | 2019-04-03 14:57:35 -0400 | [diff] [blame] | 3179 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | bool ValidateMemoryObjectParameterivEXT(Context *context, |
| 3183 | GLuint memoryObject, |
| 3184 | GLenum pname, |
| 3185 | const GLint *params) |
| 3186 | { |
| 3187 | if (!context->getExtensions().memoryObject) |
| 3188 | { |
| 3189 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3190 | return false; |
| 3191 | } |
| 3192 | |
| 3193 | UNIMPLEMENTED(); |
| 3194 | return false; |
| 3195 | } |
| 3196 | |
| 3197 | bool ValidateTexStorageMem2DEXT(Context *context, |
| 3198 | TextureType target, |
| 3199 | GLsizei levels, |
| 3200 | GLenum internalFormat, |
| 3201 | GLsizei width, |
| 3202 | GLsizei height, |
| 3203 | GLuint memory, |
| 3204 | GLuint64 offset) |
| 3205 | { |
| 3206 | if (!context->getExtensions().memoryObject) |
| 3207 | { |
| 3208 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3209 | return false; |
| 3210 | } |
| 3211 | |
Michael Spang | f02a767 | 2019-04-09 18:45:23 -0400 | [diff] [blame] | 3212 | if (context->getClientMajorVersion() < 3) |
| 3213 | { |
| 3214 | return ValidateES2TexStorageParameters(context, target, levels, internalFormat, width, |
| 3215 | height); |
| 3216 | } |
| 3217 | |
| 3218 | ASSERT(context->getClientMajorVersion() >= 3); |
| 3219 | return ValidateES3TexStorage2DParameters(context, target, levels, internalFormat, width, height, |
| 3220 | 1); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | bool ValidateTexStorageMem3DEXT(Context *context, |
| 3224 | TextureType target, |
| 3225 | GLsizei levels, |
| 3226 | GLenum internalFormat, |
| 3227 | GLsizei width, |
| 3228 | GLsizei height, |
| 3229 | GLsizei depth, |
| 3230 | GLuint memory, |
| 3231 | GLuint64 offset) |
| 3232 | { |
| 3233 | if (!context->getExtensions().memoryObject) |
| 3234 | { |
| 3235 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3236 | return false; |
| 3237 | } |
| 3238 | |
| 3239 | UNIMPLEMENTED(); |
| 3240 | return false; |
| 3241 | } |
| 3242 | |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3243 | bool ValidateImportMemoryFdEXT(Context *context, |
| 3244 | GLuint memory, |
| 3245 | GLuint64 size, |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3246 | HandleType handleType, |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3247 | GLint fd) |
| 3248 | { |
| 3249 | if (!context->getExtensions().memoryObjectFd) |
| 3250 | { |
| 3251 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3252 | return false; |
| 3253 | } |
| 3254 | |
Michael Spang | 3b2c6bf | 2019-04-16 17:19:50 -0400 | [diff] [blame] | 3255 | switch (handleType) |
| 3256 | { |
| 3257 | case HandleType::OpaqueFd: |
| 3258 | break; |
| 3259 | default: |
| 3260 | context->validationError(GL_INVALID_ENUM, kInvalidHandleType); |
| 3261 | return false; |
| 3262 | } |
| 3263 | |
| 3264 | return true; |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3265 | } |
| 3266 | |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3267 | bool ValidateDeleteSemaphoresEXT(Context *context, GLsizei n, const GLuint *semaphores) |
| 3268 | { |
| 3269 | if (!context->getExtensions().semaphore) |
| 3270 | { |
| 3271 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3272 | return false; |
| 3273 | } |
| 3274 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame^] | 3275 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | bool ValidateGenSemaphoresEXT(Context *context, GLsizei n, GLuint *semaphores) |
| 3279 | { |
| 3280 | if (!context->getExtensions().semaphore) |
| 3281 | { |
| 3282 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3283 | return false; |
| 3284 | } |
| 3285 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame^] | 3286 | return ValidateGenOrDelete(context, n); |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | bool ValidateGetSemaphoreParameterui64vEXT(Context *context, |
| 3290 | GLuint semaphore, |
| 3291 | GLenum pname, |
| 3292 | GLuint64 *params) |
| 3293 | { |
| 3294 | if (!context->getExtensions().semaphore) |
| 3295 | { |
| 3296 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3297 | return false; |
| 3298 | } |
| 3299 | |
| 3300 | UNIMPLEMENTED(); |
| 3301 | return false; |
| 3302 | } |
| 3303 | |
| 3304 | bool ValidateIsSemaphoreEXT(Context *context, GLuint semaphore) |
| 3305 | { |
| 3306 | if (!context->getExtensions().semaphore) |
| 3307 | { |
| 3308 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3309 | return false; |
| 3310 | } |
| 3311 | |
Michael Spang | 5093ba6 | 2019-05-14 17:36:36 -0400 | [diff] [blame^] | 3312 | return true; |
Michael Spang | 7a8c3e5 | 2019-04-03 14:49:57 -0400 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | bool ValidateSemaphoreParameterui64vEXT(Context *context, |
| 3316 | GLuint semaphore, |
| 3317 | GLenum pname, |
| 3318 | const GLuint64 *params) |
| 3319 | { |
| 3320 | if (!context->getExtensions().semaphore) |
| 3321 | { |
| 3322 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3323 | return false; |
| 3324 | } |
| 3325 | |
| 3326 | UNIMPLEMENTED(); |
| 3327 | return false; |
| 3328 | } |
| 3329 | |
| 3330 | bool ValidateSignalSemaphoreEXT(Context *context, |
| 3331 | GLuint semaphore, |
| 3332 | GLuint numBufferBarriers, |
| 3333 | const GLuint *buffers, |
| 3334 | GLuint numTextureBarriers, |
| 3335 | const GLuint *textures, |
| 3336 | const GLenum *dstLayouts) |
| 3337 | { |
| 3338 | if (!context->getExtensions().semaphore) |
| 3339 | { |
| 3340 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3341 | return false; |
| 3342 | } |
| 3343 | |
| 3344 | UNIMPLEMENTED(); |
| 3345 | return false; |
| 3346 | } |
| 3347 | |
| 3348 | bool ValidateWaitSemaphoreEXT(Context *context, |
| 3349 | GLuint semaphore, |
| 3350 | GLuint numBufferBarriers, |
| 3351 | const GLuint *buffers, |
| 3352 | GLuint numTextureBarriers, |
| 3353 | const GLuint *textures, |
| 3354 | const GLenum *srcLayouts) |
| 3355 | { |
| 3356 | if (!context->getExtensions().semaphore) |
| 3357 | { |
| 3358 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3359 | return false; |
| 3360 | } |
| 3361 | |
| 3362 | UNIMPLEMENTED(); |
| 3363 | return false; |
| 3364 | } |
| 3365 | |
Michael Spang | e0da9ce | 2019-04-16 14:34:51 -0400 | [diff] [blame] | 3366 | bool ValidateImportSemaphoreFdEXT(Context *context, |
| 3367 | GLuint semaphore, |
| 3368 | HandleType handleType, |
| 3369 | GLint fd) |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3370 | { |
| 3371 | if (!context->getExtensions().semaphoreFd) |
| 3372 | { |
| 3373 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 3374 | return false; |
| 3375 | } |
| 3376 | |
| 3377 | UNIMPLEMENTED(); |
| 3378 | return false; |
| 3379 | } |
| 3380 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3381 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3382 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3383 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3384 | ASSERT(buffer != nullptr); |
| 3385 | |
| 3386 | // Check if this buffer is currently being used as a transform feedback output buffer |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3387 | TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3388 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 3389 | { |
| 3390 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3391 | { |
| 3392 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3393 | if (transformFeedbackBuffer.get() == buffer) |
| 3394 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3395 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3396 | return false; |
| 3397 | } |
| 3398 | } |
| 3399 | } |
| 3400 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3401 | if (context->getExtensions().webglCompatibility && |
| 3402 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3403 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3404 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3405 | return false; |
| 3406 | } |
| 3407 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3408 | return true; |
| 3409 | } |
| 3410 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3411 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3412 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3413 | GLintptr offset, |
| 3414 | GLsizeiptr length) |
| 3415 | { |
| 3416 | if (!context->getExtensions().mapBufferRange) |
| 3417 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3418 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3419 | return false; |
| 3420 | } |
| 3421 | |
| 3422 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3423 | } |
| 3424 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3425 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 3426 | GLuint program, |
| 3427 | GLint location, |
| 3428 | const GLchar *name) |
| 3429 | { |
| 3430 | if (!context->getExtensions().bindUniformLocation) |
| 3431 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3432 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3433 | return false; |
| 3434 | } |
| 3435 | |
| 3436 | Program *programObject = GetValidProgram(context, program); |
| 3437 | if (!programObject) |
| 3438 | { |
| 3439 | return false; |
| 3440 | } |
| 3441 | |
| 3442 | if (location < 0) |
| 3443 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3444 | context->validationError(GL_INVALID_VALUE, kNegativeLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3445 | return false; |
| 3446 | } |
| 3447 | |
| 3448 | const Caps &caps = context->getCaps(); |
| 3449 | if (static_cast<size_t>(location) >= |
| 3450 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3451 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3452 | context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3453 | return false; |
| 3454 | } |
| 3455 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3456 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3457 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3458 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3459 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3460 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3461 | return false; |
| 3462 | } |
| 3463 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3464 | if (strncmp(name, "gl_", 3) == 0) |
| 3465 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3466 | context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3467 | return false; |
| 3468 | } |
| 3469 | |
| 3470 | return true; |
| 3471 | } |
| 3472 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3473 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3474 | { |
| 3475 | if (!context->getExtensions().framebufferMixedSamples) |
| 3476 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3477 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3478 | return false; |
| 3479 | } |
| 3480 | switch (components) |
| 3481 | { |
| 3482 | case GL_RGB: |
| 3483 | case GL_RGBA: |
| 3484 | case GL_ALPHA: |
| 3485 | case GL_NONE: |
| 3486 | break; |
| 3487 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3488 | context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3489 | return false; |
| 3490 | } |
| 3491 | |
| 3492 | return true; |
| 3493 | } |
| 3494 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3495 | // CHROMIUM_path_rendering |
| 3496 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3497 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3498 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3499 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3500 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3501 | return false; |
| 3502 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3503 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3504 | if (matrix == nullptr) |
| 3505 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3506 | context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3507 | return false; |
| 3508 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3509 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3510 | return true; |
| 3511 | } |
| 3512 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3513 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3514 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3515 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3516 | } |
| 3517 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3518 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3519 | { |
| 3520 | if (!context->getExtensions().pathRendering) |
| 3521 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3522 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3523 | return false; |
| 3524 | } |
| 3525 | |
| 3526 | // range = 0 is undefined in NV_path_rendering. |
| 3527 | // we add stricter semantic check here and require a non zero positive range. |
| 3528 | if (range <= 0) |
| 3529 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3530 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3531 | return false; |
| 3532 | } |
| 3533 | |
| 3534 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3535 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3536 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3537 | return false; |
| 3538 | } |
| 3539 | |
| 3540 | return true; |
| 3541 | } |
| 3542 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3543 | bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3544 | { |
| 3545 | if (!context->getExtensions().pathRendering) |
| 3546 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3547 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3548 | return false; |
| 3549 | } |
| 3550 | |
| 3551 | // range = 0 is undefined in NV_path_rendering. |
| 3552 | // we add stricter semantic check here and require a non zero positive range. |
| 3553 | if (range <= 0) |
| 3554 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3555 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3556 | return false; |
| 3557 | } |
| 3558 | |
| 3559 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 3560 | checkedRange += range; |
| 3561 | |
| 3562 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3563 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3564 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3565 | return false; |
| 3566 | } |
| 3567 | return true; |
| 3568 | } |
| 3569 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3570 | bool ValidatePathCommandsCHROMIUM(Context *context, |
| 3571 | GLuint path, |
| 3572 | GLsizei numCommands, |
| 3573 | const GLubyte *commands, |
| 3574 | GLsizei numCoords, |
| 3575 | GLenum coordType, |
| 3576 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3577 | { |
| 3578 | if (!context->getExtensions().pathRendering) |
| 3579 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3580 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3581 | return false; |
| 3582 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3583 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3584 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3585 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3586 | return false; |
| 3587 | } |
| 3588 | |
| 3589 | if (numCommands < 0) |
| 3590 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3591 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3592 | return false; |
| 3593 | } |
| 3594 | else if (numCommands > 0) |
| 3595 | { |
| 3596 | if (!commands) |
| 3597 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3598 | context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3599 | return false; |
| 3600 | } |
| 3601 | } |
| 3602 | |
| 3603 | if (numCoords < 0) |
| 3604 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3605 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3606 | return false; |
| 3607 | } |
| 3608 | else if (numCoords > 0) |
| 3609 | { |
| 3610 | if (!coords) |
| 3611 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3612 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3613 | return false; |
| 3614 | } |
| 3615 | } |
| 3616 | |
| 3617 | std::uint32_t coordTypeSize = 0; |
| 3618 | switch (coordType) |
| 3619 | { |
| 3620 | case GL_BYTE: |
| 3621 | coordTypeSize = sizeof(GLbyte); |
| 3622 | break; |
| 3623 | |
| 3624 | case GL_UNSIGNED_BYTE: |
| 3625 | coordTypeSize = sizeof(GLubyte); |
| 3626 | break; |
| 3627 | |
| 3628 | case GL_SHORT: |
| 3629 | coordTypeSize = sizeof(GLshort); |
| 3630 | break; |
| 3631 | |
| 3632 | case GL_UNSIGNED_SHORT: |
| 3633 | coordTypeSize = sizeof(GLushort); |
| 3634 | break; |
| 3635 | |
| 3636 | case GL_FLOAT: |
| 3637 | coordTypeSize = sizeof(GLfloat); |
| 3638 | break; |
| 3639 | |
| 3640 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3641 | context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3642 | return false; |
| 3643 | } |
| 3644 | |
| 3645 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3646 | checkedSize += (coordTypeSize * numCoords); |
| 3647 | if (!checkedSize.IsValid()) |
| 3648 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3649 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3650 | return false; |
| 3651 | } |
| 3652 | |
| 3653 | // early return skips command data validation when it doesn't exist. |
| 3654 | if (!commands) |
| 3655 | return true; |
| 3656 | |
| 3657 | GLsizei expectedNumCoords = 0; |
| 3658 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3659 | { |
| 3660 | switch (commands[i]) |
| 3661 | { |
| 3662 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3663 | break; |
| 3664 | case GL_MOVE_TO_CHROMIUM: |
| 3665 | case GL_LINE_TO_CHROMIUM: |
| 3666 | expectedNumCoords += 2; |
| 3667 | break; |
| 3668 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3669 | expectedNumCoords += 4; |
| 3670 | break; |
| 3671 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3672 | expectedNumCoords += 6; |
| 3673 | break; |
| 3674 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3675 | expectedNumCoords += 5; |
| 3676 | break; |
| 3677 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3678 | context->validationError(GL_INVALID_ENUM, kInvalidPathCommand); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3679 | return false; |
| 3680 | } |
| 3681 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3682 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3683 | if (expectedNumCoords != numCoords) |
| 3684 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3685 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3686 | return false; |
| 3687 | } |
| 3688 | |
| 3689 | return true; |
| 3690 | } |
| 3691 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3692 | bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3693 | { |
| 3694 | if (!context->getExtensions().pathRendering) |
| 3695 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3696 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3697 | return false; |
| 3698 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3699 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3700 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3701 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3702 | return false; |
| 3703 | } |
| 3704 | |
| 3705 | switch (pname) |
| 3706 | { |
| 3707 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3708 | if (value < 0.0f) |
| 3709 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3710 | context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3711 | return false; |
| 3712 | } |
| 3713 | break; |
| 3714 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3715 | switch (static_cast<GLenum>(value)) |
| 3716 | { |
| 3717 | case GL_FLAT_CHROMIUM: |
| 3718 | case GL_SQUARE_CHROMIUM: |
| 3719 | case GL_ROUND_CHROMIUM: |
| 3720 | break; |
| 3721 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3722 | context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3723 | return false; |
| 3724 | } |
| 3725 | break; |
| 3726 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3727 | switch (static_cast<GLenum>(value)) |
| 3728 | { |
| 3729 | case GL_MITER_REVERT_CHROMIUM: |
| 3730 | case GL_BEVEL_CHROMIUM: |
| 3731 | case GL_ROUND_CHROMIUM: |
| 3732 | break; |
| 3733 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3734 | context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3735 | return false; |
| 3736 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3737 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3738 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3739 | if (value < 0.0f) |
| 3740 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3741 | context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3742 | return false; |
| 3743 | } |
| 3744 | break; |
| 3745 | |
| 3746 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3747 | // no errors, only clamping. |
| 3748 | break; |
| 3749 | |
| 3750 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3751 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3752 | return false; |
| 3753 | } |
| 3754 | return true; |
| 3755 | } |
| 3756 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3757 | bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value) |
| 3758 | { |
| 3759 | // TODO(jmadill): Use proper clamping cast. |
| 3760 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3761 | } |
| 3762 | |
| 3763 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3764 | { |
| 3765 | if (!context->getExtensions().pathRendering) |
| 3766 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3767 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3768 | return false; |
| 3769 | } |
| 3770 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3771 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3772 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3773 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3774 | return false; |
| 3775 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3776 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3777 | if (!value) |
| 3778 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3779 | context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3780 | return false; |
| 3781 | } |
| 3782 | |
| 3783 | switch (pname) |
| 3784 | { |
| 3785 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3786 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3787 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3788 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3789 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3790 | break; |
| 3791 | |
| 3792 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3793 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3794 | return false; |
| 3795 | } |
| 3796 | |
| 3797 | return true; |
| 3798 | } |
| 3799 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3800 | bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value) |
| 3801 | { |
| 3802 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3803 | reinterpret_cast<GLfloat *>(value)); |
| 3804 | } |
| 3805 | |
| 3806 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3807 | { |
| 3808 | if (!context->getExtensions().pathRendering) |
| 3809 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3810 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3811 | return false; |
| 3812 | } |
| 3813 | |
| 3814 | switch (func) |
| 3815 | { |
| 3816 | case GL_NEVER: |
| 3817 | case GL_ALWAYS: |
| 3818 | case GL_LESS: |
| 3819 | case GL_LEQUAL: |
| 3820 | case GL_EQUAL: |
| 3821 | case GL_GEQUAL: |
| 3822 | case GL_GREATER: |
| 3823 | case GL_NOTEQUAL: |
| 3824 | break; |
| 3825 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3826 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3827 | return false; |
| 3828 | } |
| 3829 | |
| 3830 | return true; |
| 3831 | } |
| 3832 | |
| 3833 | // Note that the spec specifies that for the path drawing commands |
| 3834 | // if the path object is not an existing path object the command |
| 3835 | // does nothing and no error is generated. |
| 3836 | // However if the path object exists but has not been specified any |
| 3837 | // commands then an error is generated. |
| 3838 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3839 | bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3840 | { |
| 3841 | if (!context->getExtensions().pathRendering) |
| 3842 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3843 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3844 | return false; |
| 3845 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3846 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3847 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3848 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3849 | return false; |
| 3850 | } |
| 3851 | |
| 3852 | switch (fillMode) |
| 3853 | { |
| 3854 | case GL_COUNT_UP_CHROMIUM: |
| 3855 | case GL_COUNT_DOWN_CHROMIUM: |
| 3856 | break; |
| 3857 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3858 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3859 | return false; |
| 3860 | } |
| 3861 | |
| 3862 | if (!isPow2(mask + 1)) |
| 3863 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3864 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3865 | return false; |
| 3866 | } |
| 3867 | |
| 3868 | return true; |
| 3869 | } |
| 3870 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3871 | bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3872 | { |
| 3873 | if (!context->getExtensions().pathRendering) |
| 3874 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3875 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3876 | return false; |
| 3877 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3878 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3879 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3880 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3881 | context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3882 | return false; |
| 3883 | } |
| 3884 | |
| 3885 | return true; |
| 3886 | } |
| 3887 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3888 | bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3889 | { |
| 3890 | if (!context->getExtensions().pathRendering) |
| 3891 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3892 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3893 | return false; |
| 3894 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3895 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3896 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3897 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3898 | return false; |
| 3899 | } |
| 3900 | |
| 3901 | switch (coverMode) |
| 3902 | { |
| 3903 | case GL_CONVEX_HULL_CHROMIUM: |
| 3904 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3905 | break; |
| 3906 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3907 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3908 | return false; |
| 3909 | } |
| 3910 | return true; |
| 3911 | } |
| 3912 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 3913 | bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3914 | { |
| 3915 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3916 | } |
| 3917 | |
| 3918 | bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3919 | { |
| 3920 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3921 | } |
| 3922 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3923 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
| 3924 | GLuint path, |
| 3925 | GLenum fillMode, |
| 3926 | GLuint mask, |
| 3927 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3928 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3929 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 3930 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3931 | } |
| 3932 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3933 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
| 3934 | GLuint path, |
| 3935 | GLint reference, |
| 3936 | GLuint mask, |
| 3937 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3938 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3939 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 3940 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3941 | } |
| 3942 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3943 | bool ValidateIsPathCHROMIUM(Context *context, GLuint path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3944 | { |
| 3945 | if (!context->getExtensions().pathRendering) |
| 3946 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3947 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3948 | return false; |
| 3949 | } |
| 3950 | return true; |
| 3951 | } |
| 3952 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3953 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 3954 | GLsizei numPaths, |
| 3955 | GLenum pathNameType, |
| 3956 | const void *paths, |
| 3957 | GLuint pathBase, |
| 3958 | GLenum coverMode, |
| 3959 | GLenum transformType, |
| 3960 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3961 | { |
| 3962 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3963 | transformType, transformValues)) |
| 3964 | return false; |
| 3965 | |
| 3966 | switch (coverMode) |
| 3967 | { |
| 3968 | case GL_CONVEX_HULL_CHROMIUM: |
| 3969 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3970 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3971 | break; |
| 3972 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3973 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3974 | return false; |
| 3975 | } |
| 3976 | |
| 3977 | return true; |
| 3978 | } |
| 3979 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3980 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3981 | GLsizei numPaths, |
| 3982 | GLenum pathNameType, |
| 3983 | const void *paths, |
| 3984 | GLuint pathBase, |
| 3985 | GLenum coverMode, |
| 3986 | GLenum transformType, |
| 3987 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3988 | { |
| 3989 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3990 | transformType, transformValues)) |
| 3991 | return false; |
| 3992 | |
| 3993 | switch (coverMode) |
| 3994 | { |
| 3995 | case GL_CONVEX_HULL_CHROMIUM: |
| 3996 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3997 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3998 | break; |
| 3999 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4000 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4001 | return false; |
| 4002 | } |
| 4003 | |
| 4004 | return true; |
| 4005 | } |
| 4006 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4007 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 4008 | GLsizei numPaths, |
| 4009 | GLenum pathNameType, |
| 4010 | const void *paths, |
| 4011 | GLuint pathBase, |
| 4012 | GLenum fillMode, |
| 4013 | GLuint mask, |
| 4014 | GLenum transformType, |
| 4015 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4016 | { |
| 4017 | |
| 4018 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4019 | transformType, transformValues)) |
| 4020 | return false; |
| 4021 | |
| 4022 | switch (fillMode) |
| 4023 | { |
| 4024 | case GL_COUNT_UP_CHROMIUM: |
| 4025 | case GL_COUNT_DOWN_CHROMIUM: |
| 4026 | break; |
| 4027 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4028 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4029 | return false; |
| 4030 | } |
| 4031 | if (!isPow2(mask + 1)) |
| 4032 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4033 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4034 | return false; |
| 4035 | } |
| 4036 | return true; |
| 4037 | } |
| 4038 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4039 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 4040 | GLsizei numPaths, |
| 4041 | GLenum pathNameType, |
| 4042 | const void *paths, |
| 4043 | GLuint pathBase, |
| 4044 | GLint reference, |
| 4045 | GLuint mask, |
| 4046 | GLenum transformType, |
| 4047 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4048 | { |
| 4049 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4050 | transformType, transformValues)) |
| 4051 | return false; |
| 4052 | |
| 4053 | // no more validation here. |
| 4054 | |
| 4055 | return true; |
| 4056 | } |
| 4057 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4058 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 4059 | GLsizei numPaths, |
| 4060 | GLenum pathNameType, |
| 4061 | const void *paths, |
| 4062 | GLuint pathBase, |
| 4063 | GLenum fillMode, |
| 4064 | GLuint mask, |
| 4065 | GLenum coverMode, |
| 4066 | GLenum transformType, |
| 4067 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4068 | { |
| 4069 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4070 | transformType, transformValues)) |
| 4071 | return false; |
| 4072 | |
| 4073 | switch (coverMode) |
| 4074 | { |
| 4075 | case GL_CONVEX_HULL_CHROMIUM: |
| 4076 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4077 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4078 | break; |
| 4079 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4080 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4081 | return false; |
| 4082 | } |
| 4083 | |
| 4084 | switch (fillMode) |
| 4085 | { |
| 4086 | case GL_COUNT_UP_CHROMIUM: |
| 4087 | case GL_COUNT_DOWN_CHROMIUM: |
| 4088 | break; |
| 4089 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4090 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4091 | return false; |
| 4092 | } |
| 4093 | if (!isPow2(mask + 1)) |
| 4094 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4095 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4096 | return false; |
| 4097 | } |
| 4098 | |
| 4099 | return true; |
| 4100 | } |
| 4101 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4102 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 4103 | GLsizei numPaths, |
| 4104 | GLenum pathNameType, |
| 4105 | const void *paths, |
| 4106 | GLuint pathBase, |
| 4107 | GLint reference, |
| 4108 | GLuint mask, |
| 4109 | GLenum coverMode, |
| 4110 | GLenum transformType, |
| 4111 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4112 | { |
| 4113 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4114 | transformType, transformValues)) |
| 4115 | return false; |
| 4116 | |
| 4117 | switch (coverMode) |
| 4118 | { |
| 4119 | case GL_CONVEX_HULL_CHROMIUM: |
| 4120 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4121 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4122 | break; |
| 4123 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4124 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4125 | return false; |
| 4126 | } |
| 4127 | |
| 4128 | return true; |
| 4129 | } |
| 4130 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4131 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
| 4132 | GLuint program, |
| 4133 | GLint location, |
| 4134 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4135 | { |
| 4136 | if (!context->getExtensions().pathRendering) |
| 4137 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4138 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4139 | return false; |
| 4140 | } |
| 4141 | |
| 4142 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 4143 | if (location >= MaxLocation) |
| 4144 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4145 | context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4146 | return false; |
| 4147 | } |
| 4148 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4149 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4150 | if (!programObject) |
| 4151 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4152 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4153 | return false; |
| 4154 | } |
| 4155 | |
| 4156 | if (!name) |
| 4157 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4158 | context->validationError(GL_INVALID_VALUE, kMissingName); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4159 | return false; |
| 4160 | } |
| 4161 | |
| 4162 | if (angle::BeginsWith(name, "gl_")) |
| 4163 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4164 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4165 | return false; |
| 4166 | } |
| 4167 | |
| 4168 | return true; |
| 4169 | } |
| 4170 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4171 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
| 4172 | GLuint program, |
| 4173 | GLint location, |
| 4174 | GLenum genMode, |
| 4175 | GLint components, |
| 4176 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4177 | { |
| 4178 | if (!context->getExtensions().pathRendering) |
| 4179 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4180 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4181 | return false; |
| 4182 | } |
| 4183 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4184 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4185 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 4186 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4187 | context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4188 | return false; |
| 4189 | } |
| 4190 | |
| 4191 | if (!programObject->isLinked()) |
| 4192 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4193 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4194 | return false; |
| 4195 | } |
| 4196 | |
| 4197 | switch (genMode) |
| 4198 | { |
| 4199 | case GL_NONE: |
| 4200 | if (components != 0) |
| 4201 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4202 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4203 | return false; |
| 4204 | } |
| 4205 | break; |
| 4206 | |
| 4207 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 4208 | case GL_EYE_LINEAR_CHROMIUM: |
| 4209 | case GL_CONSTANT_CHROMIUM: |
| 4210 | if (components < 1 || components > 4) |
| 4211 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4212 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4213 | return false; |
| 4214 | } |
| 4215 | if (!coeffs) |
| 4216 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4217 | context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4218 | return false; |
| 4219 | } |
| 4220 | break; |
| 4221 | |
| 4222 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4223 | context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4224 | return false; |
| 4225 | } |
| 4226 | |
| 4227 | // If the location is -1 then the command is silently ignored |
| 4228 | // and no further validation is needed. |
| 4229 | if (location == -1) |
| 4230 | return true; |
| 4231 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 4232 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4233 | |
| 4234 | if (!binding.valid) |
| 4235 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4236 | context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4237 | return false; |
| 4238 | } |
| 4239 | |
| 4240 | if (binding.type != GL_NONE) |
| 4241 | { |
| 4242 | GLint expectedComponents = 0; |
| 4243 | switch (binding.type) |
| 4244 | { |
| 4245 | case GL_FLOAT: |
| 4246 | expectedComponents = 1; |
| 4247 | break; |
| 4248 | case GL_FLOAT_VEC2: |
| 4249 | expectedComponents = 2; |
| 4250 | break; |
| 4251 | case GL_FLOAT_VEC3: |
| 4252 | expectedComponents = 3; |
| 4253 | break; |
| 4254 | case GL_FLOAT_VEC4: |
| 4255 | expectedComponents = 4; |
| 4256 | break; |
| 4257 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4258 | context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4259 | return false; |
| 4260 | } |
| 4261 | if (expectedComponents != components && genMode != GL_NONE) |
| 4262 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4263 | context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4264 | return false; |
| 4265 | } |
| 4266 | } |
| 4267 | return true; |
| 4268 | } |
| 4269 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4270 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 4271 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4272 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4273 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4274 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4275 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4276 | GLint internalFormat, |
| 4277 | GLenum destType, |
| 4278 | GLboolean unpackFlipY, |
| 4279 | GLboolean unpackPremultiplyAlpha, |
| 4280 | GLboolean unpackUnmultiplyAlpha) |
| 4281 | { |
| 4282 | if (!context->getExtensions().copyTexture) |
| 4283 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4284 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4285 | return false; |
| 4286 | } |
| 4287 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4288 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4289 | if (source == nullptr) |
| 4290 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4291 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4292 | return false; |
| 4293 | } |
| 4294 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4295 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4296 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4297 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4298 | return false; |
| 4299 | } |
| 4300 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4301 | TextureType sourceType = source->getType(); |
| 4302 | ASSERT(sourceType != TextureType::CubeMap); |
| 4303 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4304 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4305 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4306 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4307 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4308 | return false; |
| 4309 | } |
| 4310 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4311 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 4312 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 4313 | if (sourceWidth == 0 || sourceHeight == 0) |
| 4314 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4315 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4316 | return false; |
| 4317 | } |
| 4318 | |
| 4319 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 4320 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4321 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4322 | context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4323 | return false; |
| 4324 | } |
| 4325 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4326 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4327 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4328 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4329 | return false; |
| 4330 | } |
| 4331 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4332 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4333 | if (dest == nullptr) |
| 4334 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4335 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4336 | return false; |
| 4337 | } |
| 4338 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4339 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4340 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4341 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4342 | return false; |
| 4343 | } |
| 4344 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4345 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4346 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4347 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4348 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4349 | return false; |
| 4350 | } |
| 4351 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4352 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 4353 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4354 | return false; |
| 4355 | } |
| 4356 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4357 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4358 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4359 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4360 | return false; |
| 4361 | } |
| 4362 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4363 | if (dest->getImmutableFormat()) |
| 4364 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4365 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4366 | return false; |
| 4367 | } |
| 4368 | |
| 4369 | return true; |
| 4370 | } |
| 4371 | |
| 4372 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 4373 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4374 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4375 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4376 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4377 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4378 | GLint xoffset, |
| 4379 | GLint yoffset, |
| 4380 | GLint x, |
| 4381 | GLint y, |
| 4382 | GLsizei width, |
| 4383 | GLsizei height, |
| 4384 | GLboolean unpackFlipY, |
| 4385 | GLboolean unpackPremultiplyAlpha, |
| 4386 | GLboolean unpackUnmultiplyAlpha) |
| 4387 | { |
| 4388 | if (!context->getExtensions().copyTexture) |
| 4389 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4390 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4391 | return false; |
| 4392 | } |
| 4393 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4394 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4395 | if (source == nullptr) |
| 4396 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4397 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4398 | return false; |
| 4399 | } |
| 4400 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4401 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4402 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4403 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4404 | return false; |
| 4405 | } |
| 4406 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4407 | TextureType sourceType = source->getType(); |
| 4408 | ASSERT(sourceType != TextureType::CubeMap); |
| 4409 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4410 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4411 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4412 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4413 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4414 | return false; |
| 4415 | } |
| 4416 | |
| 4417 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4418 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4419 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4420 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4421 | return false; |
| 4422 | } |
| 4423 | |
| 4424 | if (x < 0 || y < 0) |
| 4425 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4426 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4427 | return false; |
| 4428 | } |
| 4429 | |
| 4430 | if (width < 0 || height < 0) |
| 4431 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4432 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4433 | return false; |
| 4434 | } |
| 4435 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4436 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4437 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4438 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4439 | context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4440 | return false; |
| 4441 | } |
| 4442 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4443 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4444 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4445 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4446 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4447 | return false; |
| 4448 | } |
| 4449 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4450 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4451 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4452 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4453 | return false; |
| 4454 | } |
| 4455 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4456 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4457 | if (dest == nullptr) |
| 4458 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4459 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4460 | return false; |
| 4461 | } |
| 4462 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4463 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4464 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4465 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4466 | return false; |
| 4467 | } |
| 4468 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4469 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4470 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4471 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4472 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4473 | return false; |
| 4474 | } |
| 4475 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4476 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4477 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4478 | context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4479 | return false; |
| 4480 | } |
| 4481 | |
| 4482 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4483 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4484 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4485 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4486 | return false; |
| 4487 | } |
| 4488 | |
| 4489 | if (xoffset < 0 || yoffset < 0) |
| 4490 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4491 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4492 | return false; |
| 4493 | } |
| 4494 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4495 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4496 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4497 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4498 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4499 | return false; |
| 4500 | } |
| 4501 | |
| 4502 | return true; |
| 4503 | } |
| 4504 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4505 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 4506 | { |
| 4507 | if (!context->getExtensions().copyCompressedTexture) |
| 4508 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4509 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4510 | return false; |
| 4511 | } |
| 4512 | |
| 4513 | const gl::Texture *source = context->getTexture(sourceId); |
| 4514 | if (source == nullptr) |
| 4515 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4516 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4517 | return false; |
| 4518 | } |
| 4519 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4520 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4521 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4522 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4523 | return false; |
| 4524 | } |
| 4525 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4526 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4527 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4528 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4529 | context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4530 | return false; |
| 4531 | } |
| 4532 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4533 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4534 | if (!sourceFormat.info->compressed) |
| 4535 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4536 | context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4537 | return false; |
| 4538 | } |
| 4539 | |
| 4540 | const gl::Texture *dest = context->getTexture(destId); |
| 4541 | if (dest == nullptr) |
| 4542 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4543 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4544 | return false; |
| 4545 | } |
| 4546 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4547 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4548 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4549 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4550 | return false; |
| 4551 | } |
| 4552 | |
| 4553 | if (dest->getImmutableFormat()) |
| 4554 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4555 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4556 | return false; |
| 4557 | } |
| 4558 | |
| 4559 | return true; |
| 4560 | } |
| 4561 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4562 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4563 | { |
| 4564 | switch (type) |
| 4565 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4566 | case ShaderType::Vertex: |
| 4567 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4568 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4569 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4570 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4571 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4572 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4573 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4574 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4575 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4576 | break; |
| 4577 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4578 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4579 | if (!context->getExtensions().geometryShader) |
| 4580 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4581 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4582 | return false; |
| 4583 | } |
| 4584 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4585 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4586 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4587 | return false; |
| 4588 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4589 | |
| 4590 | return true; |
| 4591 | } |
| 4592 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4593 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4594 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4595 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4596 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4597 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4598 | { |
| 4599 | if (size < 0) |
| 4600 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4601 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4602 | return false; |
| 4603 | } |
| 4604 | |
| 4605 | switch (usage) |
| 4606 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4607 | case BufferUsage::StreamDraw: |
| 4608 | case BufferUsage::StaticDraw: |
| 4609 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4610 | break; |
| 4611 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4612 | case BufferUsage::StreamRead: |
| 4613 | case BufferUsage::StaticRead: |
| 4614 | case BufferUsage::DynamicRead: |
| 4615 | case BufferUsage::StreamCopy: |
| 4616 | case BufferUsage::StaticCopy: |
| 4617 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4618 | if (context->getClientMajorVersion() < 3) |
| 4619 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4620 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4621 | return false; |
| 4622 | } |
| 4623 | break; |
| 4624 | |
| 4625 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4626 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4627 | return false; |
| 4628 | } |
| 4629 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4630 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4631 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4632 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4633 | return false; |
| 4634 | } |
| 4635 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4636 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4637 | |
| 4638 | if (!buffer) |
| 4639 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4640 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4641 | return false; |
| 4642 | } |
| 4643 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4644 | if (context->getExtensions().webglCompatibility && |
| 4645 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4646 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4647 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4648 | return false; |
| 4649 | } |
| 4650 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4651 | return true; |
| 4652 | } |
| 4653 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4654 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4655 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4656 | GLintptr offset, |
| 4657 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4658 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4659 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4660 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4661 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4662 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4663 | return false; |
| 4664 | } |
| 4665 | |
| 4666 | if (offset < 0) |
| 4667 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4668 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4669 | return false; |
| 4670 | } |
| 4671 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4672 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4673 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4674 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4675 | return false; |
| 4676 | } |
| 4677 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4678 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4679 | |
| 4680 | if (!buffer) |
| 4681 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4682 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4683 | return false; |
| 4684 | } |
| 4685 | |
| 4686 | if (buffer->isMapped()) |
| 4687 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4688 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4689 | return false; |
| 4690 | } |
| 4691 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4692 | if (context->getExtensions().webglCompatibility && |
| 4693 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4694 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4695 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4696 | return false; |
| 4697 | } |
| 4698 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4699 | // Check for possible overflow of size + offset |
| 4700 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4701 | checkedSize += offset; |
| 4702 | if (!checkedSize.IsValid()) |
| 4703 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4704 | context->validationError(GL_INVALID_VALUE, kParamOverflow); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4705 | return false; |
| 4706 | } |
| 4707 | |
| 4708 | if (size + offset > buffer->getSize()) |
| 4709 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4710 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4711 | return false; |
| 4712 | } |
| 4713 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4714 | return true; |
| 4715 | } |
| 4716 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4717 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4718 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4719 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4720 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4721 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4722 | return false; |
| 4723 | } |
| 4724 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4725 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4726 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4727 | context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4728 | return false; |
| 4729 | } |
| 4730 | |
| 4731 | return true; |
| 4732 | } |
| 4733 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4734 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4735 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4736 | if (context->getClientMajorVersion() < 2) |
| 4737 | { |
| 4738 | return ValidateMultitextureUnit(context, texture); |
| 4739 | } |
| 4740 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4741 | if (texture < GL_TEXTURE0 || |
| 4742 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4743 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4744 | context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4745 | return false; |
| 4746 | } |
| 4747 | |
| 4748 | return true; |
| 4749 | } |
| 4750 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4751 | bool ValidateAttachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4752 | { |
| 4753 | Program *programObject = GetValidProgram(context, program); |
| 4754 | if (!programObject) |
| 4755 | { |
| 4756 | return false; |
| 4757 | } |
| 4758 | |
| 4759 | Shader *shaderObject = GetValidShader(context, shader); |
| 4760 | if (!shaderObject) |
| 4761 | { |
| 4762 | return false; |
| 4763 | } |
| 4764 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4765 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4766 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4767 | context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4768 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | return true; |
| 4772 | } |
| 4773 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4774 | bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4775 | { |
| 4776 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4777 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4778 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4779 | return false; |
| 4780 | } |
| 4781 | |
| 4782 | if (strncmp(name, "gl_", 3) == 0) |
| 4783 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4784 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4785 | return false; |
| 4786 | } |
| 4787 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4788 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4789 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4790 | const size_t length = strlen(name); |
| 4791 | |
| 4792 | if (!IsValidESSLString(name, length)) |
| 4793 | { |
| 4794 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4795 | // for shader-related entry points |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4796 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4797 | return false; |
| 4798 | } |
| 4799 | |
| 4800 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4801 | { |
| 4802 | return false; |
| 4803 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4804 | } |
| 4805 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4806 | return GetValidProgram(context, program) != nullptr; |
| 4807 | } |
| 4808 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4809 | bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4810 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4811 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4812 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4813 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4814 | return false; |
| 4815 | } |
| 4816 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4817 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4818 | !context->isFramebufferGenerated(framebuffer)) |
| 4819 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4820 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4821 | return false; |
| 4822 | } |
| 4823 | |
| 4824 | return true; |
| 4825 | } |
| 4826 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4827 | bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4828 | { |
| 4829 | if (target != GL_RENDERBUFFER) |
| 4830 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4831 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4832 | return false; |
| 4833 | } |
| 4834 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4835 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4836 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4837 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4838 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4839 | return false; |
| 4840 | } |
| 4841 | |
| 4842 | return true; |
| 4843 | } |
| 4844 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4845 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4846 | { |
| 4847 | switch (mode) |
| 4848 | { |
| 4849 | case GL_FUNC_ADD: |
| 4850 | case GL_FUNC_SUBTRACT: |
| 4851 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4852 | return true; |
| 4853 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4854 | case GL_MIN: |
| 4855 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4856 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4857 | |
| 4858 | default: |
| 4859 | return false; |
| 4860 | } |
| 4861 | } |
| 4862 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4863 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4864 | { |
| 4865 | return true; |
| 4866 | } |
| 4867 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4868 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4869 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4870 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4871 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4872 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4873 | return false; |
| 4874 | } |
| 4875 | |
| 4876 | return true; |
| 4877 | } |
| 4878 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4879 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4880 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4881 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4882 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4883 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4884 | return false; |
| 4885 | } |
| 4886 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4887 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4888 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4889 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4890 | return false; |
| 4891 | } |
| 4892 | |
| 4893 | return true; |
| 4894 | } |
| 4895 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4896 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4897 | { |
| 4898 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 4899 | } |
| 4900 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4901 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4902 | GLenum srcRGB, |
| 4903 | GLenum dstRGB, |
| 4904 | GLenum srcAlpha, |
| 4905 | GLenum dstAlpha) |
| 4906 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4907 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4908 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4909 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4910 | return false; |
| 4911 | } |
| 4912 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4913 | if (!ValidDstBlendFunc(context, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4914 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4915 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4916 | return false; |
| 4917 | } |
| 4918 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4919 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4920 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4921 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4922 | return false; |
| 4923 | } |
| 4924 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4925 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4926 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4927 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4928 | return false; |
| 4929 | } |
| 4930 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4931 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 4932 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4933 | { |
| 4934 | bool constantColorUsed = |
| 4935 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 4936 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 4937 | |
| 4938 | bool constantAlphaUsed = |
| 4939 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 4940 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 4941 | |
| 4942 | if (constantColorUsed && constantAlphaUsed) |
| 4943 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4944 | if (context->getExtensions().webglCompatibility) |
| 4945 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4946 | context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor); |
| 4947 | return false; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4948 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4949 | |
| 4950 | WARN() << kConstantColorAlphaLimitation; |
| 4951 | context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4952 | return false; |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | return true; |
| 4957 | } |
| 4958 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4959 | bool ValidateGetString(Context *context, GLenum name) |
| 4960 | { |
| 4961 | switch (name) |
| 4962 | { |
| 4963 | case GL_VENDOR: |
| 4964 | case GL_RENDERER: |
| 4965 | case GL_VERSION: |
| 4966 | case GL_SHADING_LANGUAGE_VERSION: |
| 4967 | case GL_EXTENSIONS: |
| 4968 | break; |
| 4969 | |
| 4970 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 4971 | if (!context->getExtensions().requestExtension) |
| 4972 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4973 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4974 | return false; |
| 4975 | } |
| 4976 | break; |
| 4977 | |
| 4978 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4979 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4980 | return false; |
| 4981 | } |
| 4982 | |
| 4983 | return true; |
| 4984 | } |
| 4985 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4986 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4987 | { |
| 4988 | if (width <= 0.0f || isNaN(width)) |
| 4989 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4990 | context->validationError(GL_INVALID_VALUE, kInvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4991 | return false; |
| 4992 | } |
| 4993 | |
| 4994 | return true; |
| 4995 | } |
| 4996 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4997 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4998 | { |
| 4999 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 5000 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5001 | context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5002 | return false; |
| 5003 | } |
| 5004 | |
| 5005 | return true; |
| 5006 | } |
| 5007 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5008 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5009 | GLenum target, |
| 5010 | GLenum internalformat, |
| 5011 | GLsizei width, |
| 5012 | GLsizei height) |
| 5013 | { |
| 5014 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 5015 | height); |
| 5016 | } |
| 5017 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5018 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5019 | GLenum target, |
| 5020 | GLsizei samples, |
| 5021 | GLenum internalformat, |
| 5022 | GLsizei width, |
| 5023 | GLsizei height) |
| 5024 | { |
| 5025 | if (!context->getExtensions().framebufferMultisample) |
| 5026 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5027 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5028 | return false; |
| 5029 | } |
| 5030 | |
| 5031 | // 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] | 5032 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5033 | // generated. |
| 5034 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 5035 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5036 | context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5037 | return false; |
| 5038 | } |
| 5039 | |
| 5040 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 5041 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 5042 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 5043 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 5044 | if (context->getClientMajorVersion() >= 3) |
| 5045 | { |
| 5046 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 5047 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 5048 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5049 | context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5050 | return false; |
| 5051 | } |
| 5052 | } |
| 5053 | |
| 5054 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 5055 | width, height); |
| 5056 | } |
| 5057 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5058 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5059 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5060 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5061 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5062 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5063 | return false; |
| 5064 | } |
| 5065 | |
| 5066 | return true; |
| 5067 | } |
| 5068 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5069 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5070 | { |
| 5071 | return true; |
| 5072 | } |
| 5073 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5074 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5075 | { |
| 5076 | return true; |
| 5077 | } |
| 5078 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5079 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5080 | { |
| 5081 | return true; |
| 5082 | } |
| 5083 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5084 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5085 | GLboolean red, |
| 5086 | GLboolean green, |
| 5087 | GLboolean blue, |
| 5088 | GLboolean alpha) |
| 5089 | { |
| 5090 | return true; |
| 5091 | } |
| 5092 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5093 | bool ValidateCompileShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5094 | { |
| 5095 | return true; |
| 5096 | } |
| 5097 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5098 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5099 | { |
| 5100 | return true; |
| 5101 | } |
| 5102 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5103 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5104 | { |
| 5105 | switch (mode) |
| 5106 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 5107 | case CullFaceMode::Front: |
| 5108 | case CullFaceMode::Back: |
| 5109 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5110 | break; |
| 5111 | |
| 5112 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5113 | context->validationError(GL_INVALID_ENUM, kInvalidCullMode); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5114 | return false; |
| 5115 | } |
| 5116 | |
| 5117 | return true; |
| 5118 | } |
| 5119 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5120 | bool ValidateDeleteProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5121 | { |
| 5122 | if (program == 0) |
| 5123 | { |
| 5124 | return false; |
| 5125 | } |
| 5126 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5127 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5128 | { |
| 5129 | if (context->getShader(program)) |
| 5130 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5131 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5132 | return false; |
| 5133 | } |
| 5134 | else |
| 5135 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5136 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5137 | return false; |
| 5138 | } |
| 5139 | } |
| 5140 | |
| 5141 | return true; |
| 5142 | } |
| 5143 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5144 | bool ValidateDeleteShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5145 | { |
| 5146 | if (shader == 0) |
| 5147 | { |
| 5148 | return false; |
| 5149 | } |
| 5150 | |
| 5151 | if (!context->getShader(shader)) |
| 5152 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5153 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5154 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5155 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5156 | return false; |
| 5157 | } |
| 5158 | else |
| 5159 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5160 | context->validationError(GL_INVALID_VALUE, kExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5161 | return false; |
| 5162 | } |
| 5163 | } |
| 5164 | |
| 5165 | return true; |
| 5166 | } |
| 5167 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5168 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5169 | { |
| 5170 | switch (func) |
| 5171 | { |
| 5172 | case GL_NEVER: |
| 5173 | case GL_ALWAYS: |
| 5174 | case GL_LESS: |
| 5175 | case GL_LEQUAL: |
| 5176 | case GL_EQUAL: |
| 5177 | case GL_GREATER: |
| 5178 | case GL_GEQUAL: |
| 5179 | case GL_NOTEQUAL: |
| 5180 | break; |
| 5181 | |
| 5182 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5183 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5184 | return false; |
| 5185 | } |
| 5186 | |
| 5187 | return true; |
| 5188 | } |
| 5189 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5190 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5191 | { |
| 5192 | return true; |
| 5193 | } |
| 5194 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5195 | bool ValidateDetachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5196 | { |
| 5197 | Program *programObject = GetValidProgram(context, program); |
| 5198 | if (!programObject) |
| 5199 | { |
| 5200 | return false; |
| 5201 | } |
| 5202 | |
| 5203 | Shader *shaderObject = GetValidShader(context, shader); |
| 5204 | if (!shaderObject) |
| 5205 | { |
| 5206 | return false; |
| 5207 | } |
| 5208 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5209 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5210 | if (attachedShader != shaderObject) |
| 5211 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5212 | context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5213 | return false; |
| 5214 | } |
| 5215 | |
| 5216 | return true; |
| 5217 | } |
| 5218 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5219 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5220 | { |
| 5221 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5222 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5223 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5224 | return false; |
| 5225 | } |
| 5226 | |
| 5227 | return true; |
| 5228 | } |
| 5229 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5230 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5231 | { |
| 5232 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5233 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5234 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5235 | return false; |
| 5236 | } |
| 5237 | |
| 5238 | return true; |
| 5239 | } |
| 5240 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5241 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5242 | { |
| 5243 | return true; |
| 5244 | } |
| 5245 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5246 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5247 | { |
| 5248 | return true; |
| 5249 | } |
| 5250 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5251 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5252 | { |
| 5253 | switch (mode) |
| 5254 | { |
| 5255 | case GL_CW: |
| 5256 | case GL_CCW: |
| 5257 | break; |
| 5258 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5259 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5260 | return false; |
| 5261 | } |
| 5262 | |
| 5263 | return true; |
| 5264 | } |
| 5265 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5266 | bool ValidateGetActiveAttrib(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5267 | GLuint program, |
| 5268 | GLuint index, |
| 5269 | GLsizei bufsize, |
| 5270 | GLsizei *length, |
| 5271 | GLint *size, |
| 5272 | GLenum *type, |
| 5273 | GLchar *name) |
| 5274 | { |
| 5275 | if (bufsize < 0) |
| 5276 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5277 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5278 | return false; |
| 5279 | } |
| 5280 | |
| 5281 | Program *programObject = GetValidProgram(context, program); |
| 5282 | |
| 5283 | if (!programObject) |
| 5284 | { |
| 5285 | return false; |
| 5286 | } |
| 5287 | |
| 5288 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 5289 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5290 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5291 | return false; |
| 5292 | } |
| 5293 | |
| 5294 | return true; |
| 5295 | } |
| 5296 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5297 | bool ValidateGetActiveUniform(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5298 | GLuint program, |
| 5299 | GLuint index, |
| 5300 | GLsizei bufsize, |
| 5301 | GLsizei *length, |
| 5302 | GLint *size, |
| 5303 | GLenum *type, |
| 5304 | GLchar *name) |
| 5305 | { |
| 5306 | if (bufsize < 0) |
| 5307 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5308 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5309 | return false; |
| 5310 | } |
| 5311 | |
| 5312 | Program *programObject = GetValidProgram(context, program); |
| 5313 | |
| 5314 | if (!programObject) |
| 5315 | { |
| 5316 | return false; |
| 5317 | } |
| 5318 | |
| 5319 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 5320 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5321 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5322 | return false; |
| 5323 | } |
| 5324 | |
| 5325 | return true; |
| 5326 | } |
| 5327 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5328 | bool ValidateGetAttachedShaders(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5329 | GLuint program, |
| 5330 | GLsizei maxcount, |
| 5331 | GLsizei *count, |
| 5332 | GLuint *shaders) |
| 5333 | { |
| 5334 | if (maxcount < 0) |
| 5335 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5336 | context->validationError(GL_INVALID_VALUE, kNegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5337 | return false; |
| 5338 | } |
| 5339 | |
| 5340 | Program *programObject = GetValidProgram(context, program); |
| 5341 | |
| 5342 | if (!programObject) |
| 5343 | { |
| 5344 | return false; |
| 5345 | } |
| 5346 | |
| 5347 | return true; |
| 5348 | } |
| 5349 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5350 | bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5351 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5352 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5353 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5354 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5355 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5356 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5357 | return false; |
| 5358 | } |
| 5359 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5360 | Program *programObject = GetValidProgram(context, program); |
| 5361 | |
| 5362 | if (!programObject) |
| 5363 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5364 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5365 | return false; |
| 5366 | } |
| 5367 | |
| 5368 | if (!programObject->isLinked()) |
| 5369 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5370 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5371 | return false; |
| 5372 | } |
| 5373 | |
| 5374 | return true; |
| 5375 | } |
| 5376 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5377 | bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5378 | { |
| 5379 | GLenum nativeType; |
| 5380 | unsigned int numParams = 0; |
| 5381 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5382 | } |
| 5383 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5384 | bool ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5385 | { |
| 5386 | return true; |
| 5387 | } |
| 5388 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5389 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5390 | { |
| 5391 | GLenum nativeType; |
| 5392 | unsigned int numParams = 0; |
| 5393 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5394 | } |
| 5395 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5396 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5397 | { |
| 5398 | GLenum nativeType; |
| 5399 | unsigned int numParams = 0; |
| 5400 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5401 | } |
| 5402 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5403 | bool ValidateGetProgramInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5404 | GLuint program, |
| 5405 | GLsizei bufsize, |
| 5406 | GLsizei *length, |
| 5407 | GLchar *infolog) |
| 5408 | { |
| 5409 | if (bufsize < 0) |
| 5410 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5411 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5412 | return false; |
| 5413 | } |
| 5414 | |
| 5415 | Program *programObject = GetValidProgram(context, program); |
| 5416 | if (!programObject) |
| 5417 | { |
| 5418 | return false; |
| 5419 | } |
| 5420 | |
| 5421 | return true; |
| 5422 | } |
| 5423 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5424 | bool ValidateGetShaderInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5425 | GLuint shader, |
| 5426 | GLsizei bufsize, |
| 5427 | GLsizei *length, |
| 5428 | GLchar *infolog) |
| 5429 | { |
| 5430 | if (bufsize < 0) |
| 5431 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5432 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5433 | return false; |
| 5434 | } |
| 5435 | |
| 5436 | Shader *shaderObject = GetValidShader(context, shader); |
| 5437 | if (!shaderObject) |
| 5438 | { |
| 5439 | return false; |
| 5440 | } |
| 5441 | |
| 5442 | return true; |
| 5443 | } |
| 5444 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5445 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5446 | GLenum shadertype, |
| 5447 | GLenum precisiontype, |
| 5448 | GLint *range, |
| 5449 | GLint *precision) |
| 5450 | { |
| 5451 | switch (shadertype) |
| 5452 | { |
| 5453 | case GL_VERTEX_SHADER: |
| 5454 | case GL_FRAGMENT_SHADER: |
| 5455 | break; |
| 5456 | case GL_COMPUTE_SHADER: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5457 | context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5458 | return false; |
| 5459 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5460 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5461 | return false; |
| 5462 | } |
| 5463 | |
| 5464 | switch (precisiontype) |
| 5465 | { |
| 5466 | case GL_LOW_FLOAT: |
| 5467 | case GL_MEDIUM_FLOAT: |
| 5468 | case GL_HIGH_FLOAT: |
| 5469 | case GL_LOW_INT: |
| 5470 | case GL_MEDIUM_INT: |
| 5471 | case GL_HIGH_INT: |
| 5472 | break; |
| 5473 | |
| 5474 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5475 | context->validationError(GL_INVALID_ENUM, kInvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5476 | return false; |
| 5477 | } |
| 5478 | |
| 5479 | return true; |
| 5480 | } |
| 5481 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5482 | bool ValidateGetShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5483 | GLuint shader, |
| 5484 | GLsizei bufsize, |
| 5485 | GLsizei *length, |
| 5486 | GLchar *source) |
| 5487 | { |
| 5488 | if (bufsize < 0) |
| 5489 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5490 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5491 | return false; |
| 5492 | } |
| 5493 | |
| 5494 | Shader *shaderObject = GetValidShader(context, shader); |
| 5495 | if (!shaderObject) |
| 5496 | { |
| 5497 | return false; |
| 5498 | } |
| 5499 | |
| 5500 | return true; |
| 5501 | } |
| 5502 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5503 | bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5504 | { |
| 5505 | if (strstr(name, "gl_") == name) |
| 5506 | { |
| 5507 | return false; |
| 5508 | } |
| 5509 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5510 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5511 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5512 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5513 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5514 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5515 | return false; |
| 5516 | } |
| 5517 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5518 | Program *programObject = GetValidProgram(context, program); |
| 5519 | |
| 5520 | if (!programObject) |
| 5521 | { |
| 5522 | return false; |
| 5523 | } |
| 5524 | |
| 5525 | if (!programObject->isLinked()) |
| 5526 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5527 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5528 | return false; |
| 5529 | } |
| 5530 | |
| 5531 | return true; |
| 5532 | } |
| 5533 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5534 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5535 | { |
| 5536 | switch (mode) |
| 5537 | { |
| 5538 | case GL_FASTEST: |
| 5539 | case GL_NICEST: |
| 5540 | case GL_DONT_CARE: |
| 5541 | break; |
| 5542 | |
| 5543 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5544 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5545 | return false; |
| 5546 | } |
| 5547 | |
| 5548 | switch (target) |
| 5549 | { |
| 5550 | case GL_GENERATE_MIPMAP_HINT: |
| 5551 | break; |
| 5552 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5553 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5554 | if (context->getClientVersion() < ES_3_0 && |
| 5555 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5556 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5557 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5558 | return false; |
| 5559 | } |
| 5560 | break; |
| 5561 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5562 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5563 | case GL_POINT_SMOOTH_HINT: |
| 5564 | case GL_LINE_SMOOTH_HINT: |
| 5565 | case GL_FOG_HINT: |
| 5566 | if (context->getClientMajorVersion() >= 2) |
| 5567 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5568 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5569 | return false; |
| 5570 | } |
| 5571 | break; |
| 5572 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5573 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5574 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5575 | return false; |
| 5576 | } |
| 5577 | |
| 5578 | return true; |
| 5579 | } |
| 5580 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5581 | bool ValidateIsBuffer(Context *context, GLuint buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5582 | { |
| 5583 | return true; |
| 5584 | } |
| 5585 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5586 | bool ValidateIsFramebuffer(Context *context, GLuint framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5587 | { |
| 5588 | return true; |
| 5589 | } |
| 5590 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5591 | bool ValidateIsProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5592 | { |
| 5593 | return true; |
| 5594 | } |
| 5595 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5596 | bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5597 | { |
| 5598 | return true; |
| 5599 | } |
| 5600 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5601 | bool ValidateIsShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5602 | { |
| 5603 | return true; |
| 5604 | } |
| 5605 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5606 | bool ValidateIsTexture(Context *context, GLuint texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5607 | { |
| 5608 | return true; |
| 5609 | } |
| 5610 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5611 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5612 | { |
| 5613 | if (context->getClientMajorVersion() < 3) |
| 5614 | { |
| 5615 | switch (pname) |
| 5616 | { |
| 5617 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5618 | case GL_UNPACK_SKIP_IMAGES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5619 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5620 | return false; |
| 5621 | |
| 5622 | case GL_UNPACK_ROW_LENGTH: |
| 5623 | case GL_UNPACK_SKIP_ROWS: |
| 5624 | case GL_UNPACK_SKIP_PIXELS: |
| 5625 | if (!context->getExtensions().unpackSubimage) |
| 5626 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5627 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5628 | return false; |
| 5629 | } |
| 5630 | break; |
| 5631 | |
| 5632 | case GL_PACK_ROW_LENGTH: |
| 5633 | case GL_PACK_SKIP_ROWS: |
| 5634 | case GL_PACK_SKIP_PIXELS: |
| 5635 | if (!context->getExtensions().packSubimage) |
| 5636 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5637 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5638 | return false; |
| 5639 | } |
| 5640 | break; |
| 5641 | } |
| 5642 | } |
| 5643 | |
| 5644 | if (param < 0) |
| 5645 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5646 | context->validationError(GL_INVALID_VALUE, kNegativeParam); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5647 | return false; |
| 5648 | } |
| 5649 | |
| 5650 | switch (pname) |
| 5651 | { |
| 5652 | case GL_UNPACK_ALIGNMENT: |
| 5653 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5654 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5655 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5656 | return false; |
| 5657 | } |
| 5658 | break; |
| 5659 | |
| 5660 | case GL_PACK_ALIGNMENT: |
| 5661 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5662 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5663 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5664 | return false; |
| 5665 | } |
| 5666 | break; |
| 5667 | |
| 5668 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5669 | if (!context->getExtensions().packReverseRowOrder) |
| 5670 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5671 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5672 | } |
| 5673 | break; |
| 5674 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5675 | case GL_UNPACK_ROW_LENGTH: |
| 5676 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5677 | case GL_UNPACK_SKIP_IMAGES: |
| 5678 | case GL_UNPACK_SKIP_ROWS: |
| 5679 | case GL_UNPACK_SKIP_PIXELS: |
| 5680 | case GL_PACK_ROW_LENGTH: |
| 5681 | case GL_PACK_SKIP_ROWS: |
| 5682 | case GL_PACK_SKIP_PIXELS: |
| 5683 | break; |
| 5684 | |
| 5685 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5686 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5687 | return false; |
| 5688 | } |
| 5689 | |
| 5690 | return true; |
| 5691 | } |
| 5692 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5693 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5694 | { |
| 5695 | return true; |
| 5696 | } |
| 5697 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5698 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5699 | { |
| 5700 | return true; |
| 5701 | } |
| 5702 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5703 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5704 | { |
| 5705 | return true; |
| 5706 | } |
| 5707 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5708 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5709 | { |
| 5710 | if (width < 0 || height < 0) |
| 5711 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5712 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5713 | return false; |
| 5714 | } |
| 5715 | |
| 5716 | return true; |
| 5717 | } |
| 5718 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5719 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5720 | GLsizei n, |
| 5721 | const GLuint *shaders, |
| 5722 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5723 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5724 | GLsizei length) |
| 5725 | { |
| 5726 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5727 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5728 | shaderBinaryFormats.end()) |
| 5729 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5730 | context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5731 | return false; |
| 5732 | } |
| 5733 | |
| 5734 | return true; |
| 5735 | } |
| 5736 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5737 | bool ValidateShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5738 | GLuint shader, |
| 5739 | GLsizei count, |
| 5740 | const GLchar *const *string, |
| 5741 | const GLint *length) |
| 5742 | { |
| 5743 | if (count < 0) |
| 5744 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5745 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5746 | return false; |
| 5747 | } |
| 5748 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5749 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5750 | // shader-related entry points |
| 5751 | if (context->getExtensions().webglCompatibility) |
| 5752 | { |
| 5753 | for (GLsizei i = 0; i < count; i++) |
| 5754 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5755 | size_t len = |
| 5756 | (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] | 5757 | |
| 5758 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5759 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5760 | context->getClientVersion() >= ES_3_0)) |
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, kShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5763 | return false; |
| 5764 | } |
| 5765 | } |
| 5766 | } |
| 5767 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5768 | Shader *shaderObject = GetValidShader(context, shader); |
| 5769 | if (!shaderObject) |
| 5770 | { |
| 5771 | return false; |
| 5772 | } |
| 5773 | |
| 5774 | return true; |
| 5775 | } |
| 5776 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5777 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5778 | { |
| 5779 | if (!IsValidStencilFunc(func)) |
| 5780 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5781 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5782 | return false; |
| 5783 | } |
| 5784 | |
| 5785 | return true; |
| 5786 | } |
| 5787 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5788 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5789 | { |
| 5790 | if (!IsValidStencilFace(face)) |
| 5791 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5792 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5793 | return false; |
| 5794 | } |
| 5795 | |
| 5796 | if (!IsValidStencilFunc(func)) |
| 5797 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5798 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5799 | return false; |
| 5800 | } |
| 5801 | |
| 5802 | return true; |
| 5803 | } |
| 5804 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5805 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5806 | { |
| 5807 | return true; |
| 5808 | } |
| 5809 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5810 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5811 | { |
| 5812 | if (!IsValidStencilFace(face)) |
| 5813 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5814 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5815 | return false; |
| 5816 | } |
| 5817 | |
| 5818 | return true; |
| 5819 | } |
| 5820 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5821 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5822 | { |
| 5823 | if (!IsValidStencilOp(fail)) |
| 5824 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5825 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5826 | return false; |
| 5827 | } |
| 5828 | |
| 5829 | if (!IsValidStencilOp(zfail)) |
| 5830 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5831 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5832 | return false; |
| 5833 | } |
| 5834 | |
| 5835 | if (!IsValidStencilOp(zpass)) |
| 5836 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5837 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5838 | return false; |
| 5839 | } |
| 5840 | |
| 5841 | return true; |
| 5842 | } |
| 5843 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5844 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5845 | GLenum face, |
| 5846 | GLenum fail, |
| 5847 | GLenum zfail, |
| 5848 | GLenum zpass) |
| 5849 | { |
| 5850 | if (!IsValidStencilFace(face)) |
| 5851 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5852 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5853 | return false; |
| 5854 | } |
| 5855 | |
| 5856 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5857 | } |
| 5858 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5859 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5860 | { |
| 5861 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5862 | } |
| 5863 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5864 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5865 | { |
| 5866 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5867 | } |
| 5868 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5869 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5870 | { |
| 5871 | return ValidateUniform1iv(context, location, 1, &x); |
| 5872 | } |
| 5873 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5874 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5875 | { |
| 5876 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 5877 | } |
| 5878 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5879 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5880 | { |
| 5881 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 5882 | } |
| 5883 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5884 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5885 | { |
| 5886 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 5887 | } |
| 5888 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5889 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5890 | { |
| 5891 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 5892 | } |
| 5893 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5894 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5895 | { |
| 5896 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 5897 | } |
| 5898 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5899 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5900 | { |
| 5901 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 5902 | } |
| 5903 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5904 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5905 | { |
| 5906 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 5907 | } |
| 5908 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5909 | 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] | 5910 | { |
| 5911 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 5912 | } |
| 5913 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5914 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5915 | { |
| 5916 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 5917 | } |
| 5918 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5919 | 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] | 5920 | { |
| 5921 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 5922 | } |
| 5923 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5924 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5925 | { |
| 5926 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 5927 | } |
| 5928 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5929 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5930 | GLint location, |
| 5931 | GLsizei count, |
| 5932 | GLboolean transpose, |
| 5933 | const GLfloat *value) |
| 5934 | { |
| 5935 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 5936 | } |
| 5937 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5938 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5939 | GLint location, |
| 5940 | GLsizei count, |
| 5941 | GLboolean transpose, |
| 5942 | const GLfloat *value) |
| 5943 | { |
| 5944 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 5945 | } |
| 5946 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5947 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5948 | GLint location, |
| 5949 | GLsizei count, |
| 5950 | GLboolean transpose, |
| 5951 | const GLfloat *value) |
| 5952 | { |
| 5953 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 5954 | } |
| 5955 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5956 | bool ValidateValidateProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5957 | { |
| 5958 | Program *programObject = GetValidProgram(context, program); |
| 5959 | |
| 5960 | if (!programObject) |
| 5961 | { |
| 5962 | return false; |
| 5963 | } |
| 5964 | |
| 5965 | return true; |
| 5966 | } |
| 5967 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5968 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5969 | { |
| 5970 | return ValidateVertexAttribIndex(context, index); |
| 5971 | } |
| 5972 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5973 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5974 | { |
| 5975 | return ValidateVertexAttribIndex(context, index); |
| 5976 | } |
| 5977 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5978 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5979 | { |
| 5980 | return ValidateVertexAttribIndex(context, index); |
| 5981 | } |
| 5982 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5983 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5984 | { |
| 5985 | return ValidateVertexAttribIndex(context, index); |
| 5986 | } |
| 5987 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5988 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5989 | { |
| 5990 | return ValidateVertexAttribIndex(context, index); |
| 5991 | } |
| 5992 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5993 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5994 | { |
| 5995 | return ValidateVertexAttribIndex(context, index); |
| 5996 | } |
| 5997 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5998 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5999 | GLuint index, |
| 6000 | GLfloat x, |
| 6001 | GLfloat y, |
| 6002 | GLfloat z, |
| 6003 | GLfloat w) |
| 6004 | { |
| 6005 | return ValidateVertexAttribIndex(context, index); |
| 6006 | } |
| 6007 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6008 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6009 | { |
| 6010 | return ValidateVertexAttribIndex(context, index); |
| 6011 | } |
| 6012 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6013 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6014 | { |
| 6015 | if (width < 0 || height < 0) |
| 6016 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6017 | context->validationError(GL_INVALID_VALUE, kViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6018 | return false; |
| 6019 | } |
| 6020 | |
| 6021 | return true; |
| 6022 | } |
| 6023 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 6024 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6025 | GLenum target, |
| 6026 | GLenum attachment, |
| 6027 | GLenum pname, |
| 6028 | GLint *params) |
| 6029 | { |
| 6030 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 6031 | nullptr); |
| 6032 | } |
| 6033 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6034 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6035 | { |
| 6036 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 6037 | } |
| 6038 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6039 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6040 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6041 | GLint level, |
| 6042 | GLenum internalformat, |
| 6043 | GLint x, |
| 6044 | GLint y, |
| 6045 | GLsizei width, |
| 6046 | GLsizei height, |
| 6047 | GLint border) |
| 6048 | { |
| 6049 | if (context->getClientMajorVersion() < 3) |
| 6050 | { |
| 6051 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 6052 | 0, x, y, width, height, border); |
| 6053 | } |
| 6054 | |
| 6055 | ASSERT(context->getClientMajorVersion() == 3); |
| 6056 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 6057 | 0, x, y, width, height, border); |
| 6058 | } |
| 6059 | |
| 6060 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6061 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6062 | GLint level, |
| 6063 | GLint xoffset, |
| 6064 | GLint yoffset, |
| 6065 | GLint x, |
| 6066 | GLint y, |
| 6067 | GLsizei width, |
| 6068 | GLsizei height) |
| 6069 | { |
| 6070 | if (context->getClientMajorVersion() < 3) |
| 6071 | { |
| 6072 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 6073 | yoffset, x, y, width, height, 0); |
| 6074 | } |
| 6075 | |
| 6076 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 6077 | yoffset, 0, x, y, width, height, 0); |
| 6078 | } |
| 6079 | |
| 6080 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 6081 | { |
| 6082 | return ValidateGenOrDelete(context, n); |
| 6083 | } |
| 6084 | |
| 6085 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 6086 | { |
| 6087 | return ValidateGenOrDelete(context, n); |
| 6088 | } |
| 6089 | |
| 6090 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 6091 | { |
| 6092 | return ValidateGenOrDelete(context, n); |
| 6093 | } |
| 6094 | |
| 6095 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 6096 | { |
| 6097 | return ValidateGenOrDelete(context, n); |
| 6098 | } |
| 6099 | |
| 6100 | bool ValidateDisable(Context *context, GLenum cap) |
| 6101 | { |
| 6102 | if (!ValidCap(context, cap, false)) |
| 6103 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6104 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6105 | return false; |
| 6106 | } |
| 6107 | |
| 6108 | return true; |
| 6109 | } |
| 6110 | |
| 6111 | bool ValidateEnable(Context *context, GLenum cap) |
| 6112 | { |
| 6113 | if (!ValidCap(context, cap, false)) |
| 6114 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6115 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6116 | return false; |
| 6117 | } |
| 6118 | |
| 6119 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 6120 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 6121 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6122 | context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6123 | |
| 6124 | // We also output an error message to the debugger window if tracing is active, so that |
| 6125 | // developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6126 | ERR() << kNoSampleAlphaToCoveragesLimitation; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6127 | return false; |
| 6128 | } |
| 6129 | |
| 6130 | return true; |
| 6131 | } |
| 6132 | |
| 6133 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 6134 | GLenum target, |
| 6135 | GLenum attachment, |
| 6136 | GLenum renderbuffertarget, |
| 6137 | GLuint renderbuffer) |
| 6138 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 6139 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6140 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6141 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6142 | return false; |
| 6143 | } |
| 6144 | |
| 6145 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0) |
| 6146 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6147 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6148 | return false; |
| 6149 | } |
| 6150 | |
| 6151 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 6152 | renderbuffertarget, renderbuffer); |
| 6153 | } |
| 6154 | |
| 6155 | bool ValidateFramebufferTexture2D(Context *context, |
| 6156 | GLenum target, |
| 6157 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6158 | TextureTarget textarget, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6159 | GLuint texture, |
| 6160 | GLint level) |
| 6161 | { |
| 6162 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 6163 | // extension |
| 6164 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 6165 | level != 0) |
| 6166 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6167 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6168 | return false; |
| 6169 | } |
| 6170 | |
| 6171 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6172 | { |
| 6173 | return false; |
| 6174 | } |
| 6175 | |
| 6176 | if (texture != 0) |
| 6177 | { |
| 6178 | gl::Texture *tex = context->getTexture(texture); |
| 6179 | ASSERT(tex); |
| 6180 | |
| 6181 | const gl::Caps &caps = context->getCaps(); |
| 6182 | |
| 6183 | switch (textarget) |
| 6184 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6185 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6186 | { |
| 6187 | if (level > gl::log2(caps.max2DTextureSize)) |
| 6188 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6189 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6190 | return false; |
| 6191 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6192 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6193 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6194 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6195 | return false; |
| 6196 | } |
| 6197 | } |
| 6198 | break; |
| 6199 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6200 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6201 | { |
| 6202 | if (level != 0) |
| 6203 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6204 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6205 | return false; |
| 6206 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6207 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6208 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6209 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6210 | return false; |
| 6211 | } |
| 6212 | } |
| 6213 | break; |
| 6214 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6215 | case TextureTarget::CubeMapNegativeX: |
| 6216 | case TextureTarget::CubeMapNegativeY: |
| 6217 | case TextureTarget::CubeMapNegativeZ: |
| 6218 | case TextureTarget::CubeMapPositiveX: |
| 6219 | case TextureTarget::CubeMapPositiveY: |
| 6220 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6221 | { |
| 6222 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6223 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6224 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6225 | return false; |
| 6226 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6227 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6228 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6229 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6230 | return false; |
| 6231 | } |
| 6232 | } |
| 6233 | break; |
| 6234 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6235 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6236 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6237 | if (context->getClientVersion() < ES_3_1 && |
| 6238 | !context->getExtensions().textureMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6239 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6240 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6241 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6242 | return false; |
| 6243 | } |
| 6244 | |
| 6245 | if (level != 0) |
| 6246 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6247 | context->validationError(GL_INVALID_VALUE, kLevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6248 | return false; |
| 6249 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6250 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6251 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6252 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6253 | return false; |
| 6254 | } |
| 6255 | } |
| 6256 | break; |
| 6257 | |
| 6258 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6259 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6260 | return false; |
| 6261 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6262 | } |
| 6263 | |
| 6264 | return true; |
| 6265 | } |
| 6266 | |
| 6267 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 6268 | { |
| 6269 | return ValidateGenOrDelete(context, n); |
| 6270 | } |
| 6271 | |
| 6272 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 6273 | { |
| 6274 | return ValidateGenOrDelete(context, n); |
| 6275 | } |
| 6276 | |
| 6277 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 6278 | { |
| 6279 | return ValidateGenOrDelete(context, n); |
| 6280 | } |
| 6281 | |
| 6282 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 6283 | { |
| 6284 | return ValidateGenOrDelete(context, n); |
| 6285 | } |
| 6286 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6287 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6288 | { |
| 6289 | if (!ValidTextureTarget(context, target)) |
| 6290 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6291 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6292 | return false; |
| 6293 | } |
| 6294 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 6295 | Texture *texture = context->getTextureByType(target); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6296 | |
| 6297 | if (texture == nullptr) |
| 6298 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6299 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6300 | return false; |
| 6301 | } |
| 6302 | |
| 6303 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6304 | |
| 6305 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6306 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6307 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6308 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6309 | context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6310 | return false; |
| 6311 | } |
| 6312 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6313 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6314 | ? TextureTarget::CubeMapPositiveX |
| 6315 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6316 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6317 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6318 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6319 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6320 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6321 | return false; |
| 6322 | } |
| 6323 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6324 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6325 | bool formatUnsized = !format.sized; |
| 6326 | bool formatColorRenderableAndFilterable = |
| 6327 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6328 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6329 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6330 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6331 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6332 | return false; |
| 6333 | } |
| 6334 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6335 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6336 | // generation |
| 6337 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6338 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6339 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6340 | return false; |
| 6341 | } |
| 6342 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6343 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6344 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6345 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6346 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6347 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6348 | return false; |
| 6349 | } |
| 6350 | |
| 6351 | // Non-power of 2 ES2 check |
| 6352 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6353 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6354 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6355 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6356 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6357 | target == TextureType::CubeMap); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6358 | context->validationError(GL_INVALID_OPERATION, kTextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6359 | return false; |
| 6360 | } |
| 6361 | |
| 6362 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6363 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6364 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6365 | context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6366 | return false; |
| 6367 | } |
| 6368 | |
James Darpinian | 83b2f0e | 2018-11-27 15:56:01 -0800 | [diff] [blame] | 6369 | if (context->getExtensions().webglCompatibility && |
| 6370 | (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 || |
| 6371 | texture->getHeight(baseTarget, effectiveBaseLevel) == 0)) |
| 6372 | { |
| 6373 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize); |
| 6374 | return false; |
| 6375 | } |
| 6376 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6377 | return true; |
| 6378 | } |
| 6379 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6380 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6381 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6382 | GLenum pname, |
| 6383 | GLint *params) |
| 6384 | { |
| 6385 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6386 | } |
| 6387 | |
| 6388 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6389 | GLenum target, |
| 6390 | GLenum pname, |
| 6391 | GLint *params) |
| 6392 | { |
| 6393 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6394 | } |
| 6395 | |
| 6396 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 6397 | { |
| 6398 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6399 | } |
| 6400 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6401 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6402 | { |
| 6403 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6404 | } |
| 6405 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6406 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6407 | { |
| 6408 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6409 | } |
| 6410 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6411 | bool ValidateGetTexParameterIivOES(Context *context, |
| 6412 | TextureType target, |
| 6413 | GLenum pname, |
| 6414 | GLint *params) |
| 6415 | { |
| 6416 | if (context->getClientMajorVersion() < 3) |
| 6417 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6418 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6419 | return false; |
| 6420 | } |
| 6421 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6422 | } |
| 6423 | |
| 6424 | bool ValidateGetTexParameterIuivOES(Context *context, |
| 6425 | TextureType target, |
| 6426 | GLenum pname, |
| 6427 | GLuint *params) |
| 6428 | { |
| 6429 | if (context->getClientMajorVersion() < 3) |
| 6430 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6431 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6432 | return false; |
| 6433 | } |
| 6434 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6435 | } |
| 6436 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6437 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 6438 | { |
| 6439 | return ValidateGetUniformBase(context, program, location); |
| 6440 | } |
| 6441 | |
| 6442 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 6443 | { |
| 6444 | return ValidateGetUniformBase(context, program, location); |
| 6445 | } |
| 6446 | |
| 6447 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6448 | { |
| 6449 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6450 | } |
| 6451 | |
| 6452 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6453 | { |
| 6454 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6455 | } |
| 6456 | |
| 6457 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6458 | { |
| 6459 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6460 | } |
| 6461 | |
| 6462 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6463 | { |
| 6464 | if (!ValidCap(context, cap, true)) |
| 6465 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6466 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6467 | return false; |
| 6468 | } |
| 6469 | |
| 6470 | return true; |
| 6471 | } |
| 6472 | |
| 6473 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 6474 | { |
| 6475 | if (context->hasActiveTransformFeedback(program)) |
| 6476 | { |
| 6477 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6478 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6479 | return false; |
| 6480 | } |
| 6481 | |
| 6482 | Program *programObject = GetValidProgram(context, program); |
| 6483 | if (!programObject) |
| 6484 | { |
| 6485 | return false; |
| 6486 | } |
| 6487 | |
| 6488 | return true; |
| 6489 | } |
| 6490 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6491 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6492 | GLint x, |
| 6493 | GLint y, |
| 6494 | GLsizei width, |
| 6495 | GLsizei height, |
| 6496 | GLenum format, |
| 6497 | GLenum type, |
| 6498 | void *pixels) |
| 6499 | { |
| 6500 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6501 | nullptr, pixels); |
| 6502 | } |
| 6503 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6504 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6505 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6506 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6507 | } |
| 6508 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6509 | bool ValidateTexParameterfv(Context *context, |
| 6510 | TextureType target, |
| 6511 | GLenum pname, |
| 6512 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6513 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6514 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6515 | } |
| 6516 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6517 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6518 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6519 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6520 | } |
| 6521 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6522 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6523 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6524 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6525 | } |
| 6526 | |
| 6527 | bool ValidateTexParameterIivOES(Context *context, |
| 6528 | TextureType target, |
| 6529 | GLenum pname, |
| 6530 | const GLint *params) |
| 6531 | { |
| 6532 | if (context->getClientMajorVersion() < 3) |
| 6533 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6534 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6535 | return false; |
| 6536 | } |
| 6537 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6538 | } |
| 6539 | |
| 6540 | bool ValidateTexParameterIuivOES(Context *context, |
| 6541 | TextureType target, |
| 6542 | GLenum pname, |
| 6543 | const GLuint *params) |
| 6544 | { |
| 6545 | if (context->getClientMajorVersion() < 3) |
| 6546 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6547 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6548 | return false; |
| 6549 | } |
| 6550 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6551 | } |
| 6552 | |
| 6553 | bool ValidateUseProgram(Context *context, GLuint program) |
| 6554 | { |
| 6555 | if (program != 0) |
| 6556 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6557 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6558 | if (!programObject) |
| 6559 | { |
| 6560 | // ES 3.1.0 section 7.3 page 72 |
| 6561 | if (context->getShader(program)) |
| 6562 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6563 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6564 | return false; |
| 6565 | } |
| 6566 | else |
| 6567 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6568 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6569 | return false; |
| 6570 | } |
| 6571 | } |
| 6572 | if (!programObject->isLinked()) |
| 6573 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6574 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6575 | return false; |
| 6576 | } |
| 6577 | } |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 6578 | if (context->getState().isTransformFeedbackActiveUnpaused()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6579 | { |
| 6580 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6581 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6582 | return false; |
| 6583 | } |
| 6584 | |
| 6585 | return true; |
| 6586 | } |
| 6587 | |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6588 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences) |
| 6589 | { |
| 6590 | if (!context->getExtensions().fence) |
| 6591 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6592 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6593 | return false; |
| 6594 | } |
| 6595 | |
| 6596 | if (n < 0) |
| 6597 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6598 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6599 | return false; |
| 6600 | } |
| 6601 | |
| 6602 | return true; |
| 6603 | } |
| 6604 | |
| 6605 | bool ValidateFinishFenceNV(Context *context, GLuint fence) |
| 6606 | { |
| 6607 | if (!context->getExtensions().fence) |
| 6608 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6609 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6610 | return false; |
| 6611 | } |
| 6612 | |
| 6613 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6614 | |
| 6615 | if (fenceObject == nullptr) |
| 6616 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6617 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6618 | return false; |
| 6619 | } |
| 6620 | |
| 6621 | if (!fenceObject->isSet()) |
| 6622 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6623 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6624 | return false; |
| 6625 | } |
| 6626 | |
| 6627 | return true; |
| 6628 | } |
| 6629 | |
| 6630 | bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences) |
| 6631 | { |
| 6632 | if (!context->getExtensions().fence) |
| 6633 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6634 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6635 | return false; |
| 6636 | } |
| 6637 | |
| 6638 | if (n < 0) |
| 6639 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6640 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6641 | return false; |
| 6642 | } |
| 6643 | |
| 6644 | return true; |
| 6645 | } |
| 6646 | |
| 6647 | bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params) |
| 6648 | { |
| 6649 | if (!context->getExtensions().fence) |
| 6650 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6651 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6652 | return false; |
| 6653 | } |
| 6654 | |
| 6655 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6656 | |
| 6657 | if (fenceObject == nullptr) |
| 6658 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6659 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6660 | return false; |
| 6661 | } |
| 6662 | |
| 6663 | if (!fenceObject->isSet()) |
| 6664 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6665 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6666 | return false; |
| 6667 | } |
| 6668 | |
| 6669 | switch (pname) |
| 6670 | { |
| 6671 | case GL_FENCE_STATUS_NV: |
| 6672 | case GL_FENCE_CONDITION_NV: |
| 6673 | break; |
| 6674 | |
| 6675 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6676 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6677 | return false; |
| 6678 | } |
| 6679 | |
| 6680 | return true; |
| 6681 | } |
| 6682 | |
| 6683 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6684 | { |
| 6685 | if (!context->getExtensions().robustness) |
| 6686 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6687 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6688 | return false; |
| 6689 | } |
| 6690 | |
| 6691 | return true; |
| 6692 | } |
| 6693 | |
| 6694 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
| 6695 | GLuint shader, |
| 6696 | GLsizei bufsize, |
| 6697 | GLsizei *length, |
| 6698 | GLchar *source) |
| 6699 | { |
| 6700 | if (!context->getExtensions().translatedShaderSource) |
| 6701 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6702 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6703 | return false; |
| 6704 | } |
| 6705 | |
| 6706 | if (bufsize < 0) |
| 6707 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6708 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6709 | return false; |
| 6710 | } |
| 6711 | |
| 6712 | Shader *shaderObject = context->getShader(shader); |
| 6713 | |
| 6714 | if (!shaderObject) |
| 6715 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6716 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6717 | return false; |
| 6718 | } |
| 6719 | |
| 6720 | return true; |
| 6721 | } |
| 6722 | |
| 6723 | bool ValidateIsFenceNV(Context *context, GLuint fence) |
| 6724 | { |
| 6725 | if (!context->getExtensions().fence) |
| 6726 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6727 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6728 | return false; |
| 6729 | } |
| 6730 | |
| 6731 | return true; |
| 6732 | } |
| 6733 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6734 | bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition) |
| 6735 | { |
| 6736 | if (!context->getExtensions().fence) |
| 6737 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6738 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6739 | return false; |
| 6740 | } |
| 6741 | |
| 6742 | if (condition != GL_ALL_COMPLETED_NV) |
| 6743 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6744 | context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6745 | return false; |
| 6746 | } |
| 6747 | |
| 6748 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6749 | |
| 6750 | if (fenceObject == nullptr) |
| 6751 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6752 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6753 | return false; |
| 6754 | } |
| 6755 | |
| 6756 | return true; |
| 6757 | } |
| 6758 | |
| 6759 | bool ValidateTestFenceNV(Context *context, GLuint fence) |
| 6760 | { |
| 6761 | if (!context->getExtensions().fence) |
| 6762 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6763 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6764 | return false; |
| 6765 | } |
| 6766 | |
| 6767 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6768 | |
| 6769 | if (fenceObject == nullptr) |
| 6770 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6771 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6772 | return false; |
| 6773 | } |
| 6774 | |
| 6775 | if (fenceObject->isSet() != GL_TRUE) |
| 6776 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6777 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6778 | return false; |
| 6779 | } |
| 6780 | |
| 6781 | return true; |
| 6782 | } |
| 6783 | |
| 6784 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6785 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6786 | GLsizei levels, |
| 6787 | GLenum internalformat, |
| 6788 | GLsizei width, |
| 6789 | GLsizei height) |
| 6790 | { |
| 6791 | if (!context->getExtensions().textureStorage) |
| 6792 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6793 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6794 | return false; |
| 6795 | } |
| 6796 | |
| 6797 | if (context->getClientMajorVersion() < 3) |
| 6798 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6799 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6800 | height); |
| 6801 | } |
| 6802 | |
| 6803 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6804 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6805 | 1); |
| 6806 | } |
| 6807 | |
| 6808 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 6809 | { |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 6810 | if (!context->getExtensions().instancedArraysANGLE) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6811 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6812 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6813 | return false; |
| 6814 | } |
| 6815 | |
| 6816 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6817 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6818 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6819 | return false; |
| 6820 | } |
| 6821 | |
| 6822 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 6823 | { |
| 6824 | if (index == 0 && divisor != 0) |
| 6825 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6826 | context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6827 | |
| 6828 | // We also output an error message to the debugger window if tracing is active, so |
| 6829 | // that developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6830 | ERR() << kAttributeZeroRequiresDivisorLimitation; |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6831 | return false; |
| 6832 | } |
| 6833 | } |
| 6834 | |
| 6835 | return true; |
| 6836 | } |
| 6837 | |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 6838 | bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor) |
| 6839 | { |
| 6840 | if (!context->getExtensions().instancedArraysEXT) |
| 6841 | { |
| 6842 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6843 | return false; |
| 6844 | } |
| 6845 | |
| 6846 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6847 | { |
| 6848 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
| 6849 | return false; |
| 6850 | } |
| 6851 | |
| 6852 | return true; |
| 6853 | } |
| 6854 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6855 | bool ValidateTexImage3DOES(Context *context, |
| 6856 | GLenum target, |
| 6857 | GLint level, |
| 6858 | GLenum internalformat, |
| 6859 | GLsizei width, |
| 6860 | GLsizei height, |
| 6861 | GLsizei depth, |
| 6862 | GLint border, |
| 6863 | GLenum format, |
| 6864 | GLenum type, |
| 6865 | const void *pixels) |
| 6866 | { |
| 6867 | UNIMPLEMENTED(); // FIXME |
| 6868 | return false; |
| 6869 | } |
| 6870 | |
| 6871 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 6872 | { |
| 6873 | if (!context->getExtensions().debugMarker) |
| 6874 | { |
| 6875 | // The debug marker calls should not set error state |
| 6876 | // 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] | 6877 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6878 | return false; |
| 6879 | } |
| 6880 | |
| 6881 | return true; |
| 6882 | } |
| 6883 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6884 | bool ValidateTexStorage1DEXT(Context *context, |
| 6885 | GLenum target, |
| 6886 | GLsizei levels, |
| 6887 | GLenum internalformat, |
| 6888 | GLsizei width) |
| 6889 | { |
| 6890 | UNIMPLEMENTED(); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6891 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6892 | return false; |
| 6893 | } |
| 6894 | |
| 6895 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6896 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6897 | GLsizei levels, |
| 6898 | GLenum internalformat, |
| 6899 | GLsizei width, |
| 6900 | GLsizei height, |
| 6901 | GLsizei depth) |
| 6902 | { |
| 6903 | if (!context->getExtensions().textureStorage) |
| 6904 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6905 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6906 | return false; |
| 6907 | } |
| 6908 | |
| 6909 | if (context->getClientMajorVersion() < 3) |
| 6910 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6911 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6912 | return false; |
| 6913 | } |
| 6914 | |
| 6915 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 6916 | depth); |
| 6917 | } |
| 6918 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6919 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 6920 | { |
| 6921 | if (!context->getExtensions().parallelShaderCompile) |
| 6922 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6923 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6924 | return false; |
| 6925 | } |
| 6926 | return true; |
| 6927 | } |
| 6928 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6929 | bool ValidateMultiDrawArraysANGLE(Context *context, |
| 6930 | PrimitiveMode mode, |
| 6931 | const GLint *firsts, |
| 6932 | const GLsizei *counts, |
| 6933 | GLsizei drawcount) |
| 6934 | { |
| 6935 | if (!context->getExtensions().multiDraw) |
| 6936 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6937 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6938 | return false; |
| 6939 | } |
| 6940 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6941 | { |
| 6942 | if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID])) |
| 6943 | { |
| 6944 | return false; |
| 6945 | } |
| 6946 | } |
| 6947 | return true; |
| 6948 | } |
| 6949 | |
| 6950 | bool ValidateMultiDrawElementsANGLE(Context *context, |
| 6951 | PrimitiveMode mode, |
| 6952 | const GLsizei *counts, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 6953 | DrawElementsType type, |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 6954 | const GLvoid *const *indices, |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6955 | GLsizei drawcount) |
| 6956 | { |
| 6957 | if (!context->getExtensions().multiDraw) |
| 6958 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6959 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6960 | return false; |
| 6961 | } |
| 6962 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6963 | { |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 6964 | if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID])) |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6965 | { |
| 6966 | return false; |
| 6967 | } |
| 6968 | } |
| 6969 | return true; |
| 6970 | } |
| 6971 | |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 6972 | bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked) |
| 6973 | { |
| 6974 | if (!context->getExtensions().provokingVertex) |
| 6975 | { |
| 6976 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6977 | return false; |
| 6978 | } |
| 6979 | |
| 6980 | switch (modePacked) |
| 6981 | { |
| 6982 | case ProvokingVertex::FirstVertexConvention: |
| 6983 | case ProvokingVertex::LastVertexConvention: |
| 6984 | break; |
| 6985 | default: |
| 6986 | context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex); |
| 6987 | return false; |
| 6988 | } |
| 6989 | |
| 6990 | return true; |
| 6991 | } |
| 6992 | |
Jamie Madill | a541048 | 2019-01-31 19:55:55 -0500 | [diff] [blame] | 6993 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 6994 | { |
| 6995 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 6996 | |
| 6997 | switch (target) |
| 6998 | { |
| 6999 | case TextureType::Rectangle: |
| 7000 | ASSERT(!context->getExtensions().textureRectangle); |
| 7001 | context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported); |
| 7002 | break; |
| 7003 | |
| 7004 | case TextureType::_3D: |
| 7005 | case TextureType::_2DArray: |
| 7006 | ASSERT(context->getClientMajorVersion() < 3); |
| 7007 | context->validationError(GL_INVALID_ENUM, kES3Required); |
| 7008 | break; |
| 7009 | |
| 7010 | case TextureType::_2DMultisample: |
| 7011 | ASSERT(context->getClientVersion() < Version(3, 1) && |
| 7012 | !context->getExtensions().textureMultisample); |
| 7013 | context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required); |
| 7014 | break; |
| 7015 | |
| 7016 | case TextureType::_2DMultisampleArray: |
| 7017 | ASSERT(!context->getExtensions().textureStorageMultisample2DArray); |
| 7018 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
| 7019 | break; |
| 7020 | |
| 7021 | case TextureType::External: |
| 7022 | ASSERT(!context->getExtensions().eglImageExternal && |
| 7023 | !context->getExtensions().eglStreamConsumerExternal); |
| 7024 | context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported); |
| 7025 | break; |
| 7026 | |
| 7027 | default: |
| 7028 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
| 7029 | } |
| 7030 | } |
| 7031 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 7032 | } // namespace gl |