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 | |
Michael Spang | 6bb193c | 2019-05-22 16:32:21 -0400 | [diff] [blame^] | 3377 | switch (handleType) |
| 3378 | { |
| 3379 | case HandleType::OpaqueFd: |
| 3380 | break; |
| 3381 | default: |
| 3382 | context->validationError(GL_INVALID_ENUM, kInvalidHandleType); |
| 3383 | return false; |
| 3384 | } |
| 3385 | |
| 3386 | return true; |
Michael Spang | 9de3ddb | 2019-04-03 16:23:40 -0400 | [diff] [blame] | 3387 | } |
| 3388 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3389 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3390 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3391 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3392 | ASSERT(buffer != nullptr); |
| 3393 | |
| 3394 | // 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] | 3395 | TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3396 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 3397 | { |
| 3398 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3399 | { |
| 3400 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3401 | if (transformFeedbackBuffer.get() == buffer) |
| 3402 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3403 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3404 | return false; |
| 3405 | } |
| 3406 | } |
| 3407 | } |
| 3408 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3409 | if (context->getExtensions().webglCompatibility && |
| 3410 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3411 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3412 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3413 | return false; |
| 3414 | } |
| 3415 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3416 | return true; |
| 3417 | } |
| 3418 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3419 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3420 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3421 | GLintptr offset, |
| 3422 | GLsizeiptr length) |
| 3423 | { |
| 3424 | if (!context->getExtensions().mapBufferRange) |
| 3425 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3426 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3427 | return false; |
| 3428 | } |
| 3429 | |
| 3430 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3431 | } |
| 3432 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3433 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 3434 | GLuint program, |
| 3435 | GLint location, |
| 3436 | const GLchar *name) |
| 3437 | { |
| 3438 | if (!context->getExtensions().bindUniformLocation) |
| 3439 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3440 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3441 | return false; |
| 3442 | } |
| 3443 | |
| 3444 | Program *programObject = GetValidProgram(context, program); |
| 3445 | if (!programObject) |
| 3446 | { |
| 3447 | return false; |
| 3448 | } |
| 3449 | |
| 3450 | if (location < 0) |
| 3451 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3452 | context->validationError(GL_INVALID_VALUE, kNegativeLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3453 | return false; |
| 3454 | } |
| 3455 | |
| 3456 | const Caps &caps = context->getCaps(); |
| 3457 | if (static_cast<size_t>(location) >= |
| 3458 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3459 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3460 | context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3461 | return false; |
| 3462 | } |
| 3463 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3464 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3465 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3466 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3467 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3468 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3469 | return false; |
| 3470 | } |
| 3471 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3472 | if (strncmp(name, "gl_", 3) == 0) |
| 3473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3474 | context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3475 | return false; |
| 3476 | } |
| 3477 | |
| 3478 | return true; |
| 3479 | } |
| 3480 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3481 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3482 | { |
| 3483 | if (!context->getExtensions().framebufferMixedSamples) |
| 3484 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3485 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3486 | return false; |
| 3487 | } |
| 3488 | switch (components) |
| 3489 | { |
| 3490 | case GL_RGB: |
| 3491 | case GL_RGBA: |
| 3492 | case GL_ALPHA: |
| 3493 | case GL_NONE: |
| 3494 | break; |
| 3495 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3496 | context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3497 | return false; |
| 3498 | } |
| 3499 | |
| 3500 | return true; |
| 3501 | } |
| 3502 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3503 | // CHROMIUM_path_rendering |
| 3504 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3505 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3506 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3507 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3508 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3509 | return false; |
| 3510 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3511 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3512 | if (matrix == nullptr) |
| 3513 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3514 | context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3515 | return false; |
| 3516 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3517 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3518 | return true; |
| 3519 | } |
| 3520 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3521 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3522 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3523 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3524 | } |
| 3525 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3526 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3527 | { |
| 3528 | if (!context->getExtensions().pathRendering) |
| 3529 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3530 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3531 | return false; |
| 3532 | } |
| 3533 | |
| 3534 | // range = 0 is undefined in NV_path_rendering. |
| 3535 | // we add stricter semantic check here and require a non zero positive range. |
| 3536 | if (range <= 0) |
| 3537 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3538 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3539 | return false; |
| 3540 | } |
| 3541 | |
| 3542 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3543 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3544 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3545 | return false; |
| 3546 | } |
| 3547 | |
| 3548 | return true; |
| 3549 | } |
| 3550 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3551 | bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3552 | { |
| 3553 | if (!context->getExtensions().pathRendering) |
| 3554 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3555 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3556 | return false; |
| 3557 | } |
| 3558 | |
| 3559 | // range = 0 is undefined in NV_path_rendering. |
| 3560 | // we add stricter semantic check here and require a non zero positive range. |
| 3561 | if (range <= 0) |
| 3562 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3563 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3564 | return false; |
| 3565 | } |
| 3566 | |
| 3567 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 3568 | checkedRange += range; |
| 3569 | |
| 3570 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3571 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3572 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3573 | return false; |
| 3574 | } |
| 3575 | return true; |
| 3576 | } |
| 3577 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3578 | bool ValidatePathCommandsCHROMIUM(Context *context, |
| 3579 | GLuint path, |
| 3580 | GLsizei numCommands, |
| 3581 | const GLubyte *commands, |
| 3582 | GLsizei numCoords, |
| 3583 | GLenum coordType, |
| 3584 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3585 | { |
| 3586 | if (!context->getExtensions().pathRendering) |
| 3587 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3588 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3589 | return false; |
| 3590 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3591 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3592 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3593 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3594 | return false; |
| 3595 | } |
| 3596 | |
| 3597 | if (numCommands < 0) |
| 3598 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3599 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3600 | return false; |
| 3601 | } |
| 3602 | else if (numCommands > 0) |
| 3603 | { |
| 3604 | if (!commands) |
| 3605 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3606 | context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3607 | return false; |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | if (numCoords < 0) |
| 3612 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3613 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3614 | return false; |
| 3615 | } |
| 3616 | else if (numCoords > 0) |
| 3617 | { |
| 3618 | if (!coords) |
| 3619 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3620 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3621 | return false; |
| 3622 | } |
| 3623 | } |
| 3624 | |
| 3625 | std::uint32_t coordTypeSize = 0; |
| 3626 | switch (coordType) |
| 3627 | { |
| 3628 | case GL_BYTE: |
| 3629 | coordTypeSize = sizeof(GLbyte); |
| 3630 | break; |
| 3631 | |
| 3632 | case GL_UNSIGNED_BYTE: |
| 3633 | coordTypeSize = sizeof(GLubyte); |
| 3634 | break; |
| 3635 | |
| 3636 | case GL_SHORT: |
| 3637 | coordTypeSize = sizeof(GLshort); |
| 3638 | break; |
| 3639 | |
| 3640 | case GL_UNSIGNED_SHORT: |
| 3641 | coordTypeSize = sizeof(GLushort); |
| 3642 | break; |
| 3643 | |
| 3644 | case GL_FLOAT: |
| 3645 | coordTypeSize = sizeof(GLfloat); |
| 3646 | break; |
| 3647 | |
| 3648 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3649 | context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3650 | return false; |
| 3651 | } |
| 3652 | |
| 3653 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3654 | checkedSize += (coordTypeSize * numCoords); |
| 3655 | if (!checkedSize.IsValid()) |
| 3656 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3657 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3658 | return false; |
| 3659 | } |
| 3660 | |
| 3661 | // early return skips command data validation when it doesn't exist. |
| 3662 | if (!commands) |
| 3663 | return true; |
| 3664 | |
| 3665 | GLsizei expectedNumCoords = 0; |
| 3666 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3667 | { |
| 3668 | switch (commands[i]) |
| 3669 | { |
| 3670 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3671 | break; |
| 3672 | case GL_MOVE_TO_CHROMIUM: |
| 3673 | case GL_LINE_TO_CHROMIUM: |
| 3674 | expectedNumCoords += 2; |
| 3675 | break; |
| 3676 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3677 | expectedNumCoords += 4; |
| 3678 | break; |
| 3679 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3680 | expectedNumCoords += 6; |
| 3681 | break; |
| 3682 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3683 | expectedNumCoords += 5; |
| 3684 | break; |
| 3685 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3686 | context->validationError(GL_INVALID_ENUM, kInvalidPathCommand); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3687 | return false; |
| 3688 | } |
| 3689 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3690 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3691 | if (expectedNumCoords != numCoords) |
| 3692 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3693 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3694 | return false; |
| 3695 | } |
| 3696 | |
| 3697 | return true; |
| 3698 | } |
| 3699 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3700 | bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3701 | { |
| 3702 | if (!context->getExtensions().pathRendering) |
| 3703 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3704 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3705 | return false; |
| 3706 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3707 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3708 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3709 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3710 | return false; |
| 3711 | } |
| 3712 | |
| 3713 | switch (pname) |
| 3714 | { |
| 3715 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3716 | if (value < 0.0f) |
| 3717 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3718 | context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3719 | return false; |
| 3720 | } |
| 3721 | break; |
| 3722 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3723 | switch (static_cast<GLenum>(value)) |
| 3724 | { |
| 3725 | case GL_FLAT_CHROMIUM: |
| 3726 | case GL_SQUARE_CHROMIUM: |
| 3727 | case GL_ROUND_CHROMIUM: |
| 3728 | break; |
| 3729 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3730 | context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3731 | return false; |
| 3732 | } |
| 3733 | break; |
| 3734 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3735 | switch (static_cast<GLenum>(value)) |
| 3736 | { |
| 3737 | case GL_MITER_REVERT_CHROMIUM: |
| 3738 | case GL_BEVEL_CHROMIUM: |
| 3739 | case GL_ROUND_CHROMIUM: |
| 3740 | break; |
| 3741 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3742 | context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3743 | return false; |
| 3744 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3745 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3746 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3747 | if (value < 0.0f) |
| 3748 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3749 | context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3750 | return false; |
| 3751 | } |
| 3752 | break; |
| 3753 | |
| 3754 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3755 | // no errors, only clamping. |
| 3756 | break; |
| 3757 | |
| 3758 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3759 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3760 | return false; |
| 3761 | } |
| 3762 | return true; |
| 3763 | } |
| 3764 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3765 | bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value) |
| 3766 | { |
| 3767 | // TODO(jmadill): Use proper clamping cast. |
| 3768 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3769 | } |
| 3770 | |
| 3771 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3772 | { |
| 3773 | if (!context->getExtensions().pathRendering) |
| 3774 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3775 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3776 | return false; |
| 3777 | } |
| 3778 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3779 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3780 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3781 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3782 | return false; |
| 3783 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3784 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3785 | if (!value) |
| 3786 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3787 | context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3788 | return false; |
| 3789 | } |
| 3790 | |
| 3791 | switch (pname) |
| 3792 | { |
| 3793 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3794 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3795 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3796 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3797 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3798 | break; |
| 3799 | |
| 3800 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3801 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3802 | return false; |
| 3803 | } |
| 3804 | |
| 3805 | return true; |
| 3806 | } |
| 3807 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3808 | bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value) |
| 3809 | { |
| 3810 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3811 | reinterpret_cast<GLfloat *>(value)); |
| 3812 | } |
| 3813 | |
| 3814 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3815 | { |
| 3816 | if (!context->getExtensions().pathRendering) |
| 3817 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3818 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3819 | return false; |
| 3820 | } |
| 3821 | |
| 3822 | switch (func) |
| 3823 | { |
| 3824 | case GL_NEVER: |
| 3825 | case GL_ALWAYS: |
| 3826 | case GL_LESS: |
| 3827 | case GL_LEQUAL: |
| 3828 | case GL_EQUAL: |
| 3829 | case GL_GEQUAL: |
| 3830 | case GL_GREATER: |
| 3831 | case GL_NOTEQUAL: |
| 3832 | break; |
| 3833 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3834 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3835 | return false; |
| 3836 | } |
| 3837 | |
| 3838 | return true; |
| 3839 | } |
| 3840 | |
| 3841 | // Note that the spec specifies that for the path drawing commands |
| 3842 | // if the path object is not an existing path object the command |
| 3843 | // does nothing and no error is generated. |
| 3844 | // However if the path object exists but has not been specified any |
| 3845 | // commands then an error is generated. |
| 3846 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3847 | bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3848 | { |
| 3849 | if (!context->getExtensions().pathRendering) |
| 3850 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3851 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3852 | return false; |
| 3853 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3854 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3855 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3856 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3857 | return false; |
| 3858 | } |
| 3859 | |
| 3860 | switch (fillMode) |
| 3861 | { |
| 3862 | case GL_COUNT_UP_CHROMIUM: |
| 3863 | case GL_COUNT_DOWN_CHROMIUM: |
| 3864 | break; |
| 3865 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3866 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3867 | return false; |
| 3868 | } |
| 3869 | |
| 3870 | if (!isPow2(mask + 1)) |
| 3871 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3872 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3873 | return false; |
| 3874 | } |
| 3875 | |
| 3876 | return true; |
| 3877 | } |
| 3878 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3879 | bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3880 | { |
| 3881 | if (!context->getExtensions().pathRendering) |
| 3882 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3883 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3884 | return false; |
| 3885 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3886 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3887 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3888 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3889 | context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3890 | return false; |
| 3891 | } |
| 3892 | |
| 3893 | return true; |
| 3894 | } |
| 3895 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3896 | bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3897 | { |
| 3898 | if (!context->getExtensions().pathRendering) |
| 3899 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3900 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3901 | return false; |
| 3902 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3903 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3904 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3905 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3906 | return false; |
| 3907 | } |
| 3908 | |
| 3909 | switch (coverMode) |
| 3910 | { |
| 3911 | case GL_CONVEX_HULL_CHROMIUM: |
| 3912 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3913 | break; |
| 3914 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3915 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3916 | return false; |
| 3917 | } |
| 3918 | return true; |
| 3919 | } |
| 3920 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 3921 | bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3922 | { |
| 3923 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3924 | } |
| 3925 | |
| 3926 | bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3927 | { |
| 3928 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3929 | } |
| 3930 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3931 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
| 3932 | GLuint path, |
| 3933 | GLenum fillMode, |
| 3934 | GLuint mask, |
| 3935 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3936 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3937 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 3938 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3939 | } |
| 3940 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3941 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
| 3942 | GLuint path, |
| 3943 | GLint reference, |
| 3944 | GLuint mask, |
| 3945 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3946 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3947 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 3948 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3949 | } |
| 3950 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3951 | bool ValidateIsPathCHROMIUM(Context *context, GLuint path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3952 | { |
| 3953 | if (!context->getExtensions().pathRendering) |
| 3954 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3955 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3956 | return false; |
| 3957 | } |
| 3958 | return true; |
| 3959 | } |
| 3960 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3961 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 3962 | GLsizei numPaths, |
| 3963 | GLenum pathNameType, |
| 3964 | const void *paths, |
| 3965 | GLuint pathBase, |
| 3966 | GLenum coverMode, |
| 3967 | GLenum transformType, |
| 3968 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3969 | { |
| 3970 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3971 | transformType, transformValues)) |
| 3972 | return false; |
| 3973 | |
| 3974 | switch (coverMode) |
| 3975 | { |
| 3976 | case GL_CONVEX_HULL_CHROMIUM: |
| 3977 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3978 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3979 | break; |
| 3980 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3981 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3982 | return false; |
| 3983 | } |
| 3984 | |
| 3985 | return true; |
| 3986 | } |
| 3987 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3988 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3989 | GLsizei numPaths, |
| 3990 | GLenum pathNameType, |
| 3991 | const void *paths, |
| 3992 | GLuint pathBase, |
| 3993 | GLenum coverMode, |
| 3994 | GLenum transformType, |
| 3995 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3996 | { |
| 3997 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3998 | transformType, transformValues)) |
| 3999 | return false; |
| 4000 | |
| 4001 | switch (coverMode) |
| 4002 | { |
| 4003 | case GL_CONVEX_HULL_CHROMIUM: |
| 4004 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4005 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4006 | break; |
| 4007 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4008 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4009 | return false; |
| 4010 | } |
| 4011 | |
| 4012 | return true; |
| 4013 | } |
| 4014 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4015 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 4016 | GLsizei numPaths, |
| 4017 | GLenum pathNameType, |
| 4018 | const void *paths, |
| 4019 | GLuint pathBase, |
| 4020 | GLenum fillMode, |
| 4021 | GLuint mask, |
| 4022 | GLenum transformType, |
| 4023 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4024 | { |
| 4025 | |
| 4026 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4027 | transformType, transformValues)) |
| 4028 | return false; |
| 4029 | |
| 4030 | switch (fillMode) |
| 4031 | { |
| 4032 | case GL_COUNT_UP_CHROMIUM: |
| 4033 | case GL_COUNT_DOWN_CHROMIUM: |
| 4034 | break; |
| 4035 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4036 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4037 | return false; |
| 4038 | } |
| 4039 | if (!isPow2(mask + 1)) |
| 4040 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4041 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4042 | return false; |
| 4043 | } |
| 4044 | return true; |
| 4045 | } |
| 4046 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4047 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 4048 | GLsizei numPaths, |
| 4049 | GLenum pathNameType, |
| 4050 | const void *paths, |
| 4051 | GLuint pathBase, |
| 4052 | GLint reference, |
| 4053 | GLuint mask, |
| 4054 | GLenum transformType, |
| 4055 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4056 | { |
| 4057 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4058 | transformType, transformValues)) |
| 4059 | return false; |
| 4060 | |
| 4061 | // no more validation here. |
| 4062 | |
| 4063 | return true; |
| 4064 | } |
| 4065 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4066 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 4067 | GLsizei numPaths, |
| 4068 | GLenum pathNameType, |
| 4069 | const void *paths, |
| 4070 | GLuint pathBase, |
| 4071 | GLenum fillMode, |
| 4072 | GLuint mask, |
| 4073 | GLenum coverMode, |
| 4074 | GLenum transformType, |
| 4075 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4076 | { |
| 4077 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4078 | transformType, transformValues)) |
| 4079 | return false; |
| 4080 | |
| 4081 | switch (coverMode) |
| 4082 | { |
| 4083 | case GL_CONVEX_HULL_CHROMIUM: |
| 4084 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4085 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4086 | break; |
| 4087 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4088 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4089 | return false; |
| 4090 | } |
| 4091 | |
| 4092 | switch (fillMode) |
| 4093 | { |
| 4094 | case GL_COUNT_UP_CHROMIUM: |
| 4095 | case GL_COUNT_DOWN_CHROMIUM: |
| 4096 | break; |
| 4097 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4098 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4099 | return false; |
| 4100 | } |
| 4101 | if (!isPow2(mask + 1)) |
| 4102 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4103 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4104 | return false; |
| 4105 | } |
| 4106 | |
| 4107 | return true; |
| 4108 | } |
| 4109 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4110 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 4111 | GLsizei numPaths, |
| 4112 | GLenum pathNameType, |
| 4113 | const void *paths, |
| 4114 | GLuint pathBase, |
| 4115 | GLint reference, |
| 4116 | GLuint mask, |
| 4117 | GLenum coverMode, |
| 4118 | GLenum transformType, |
| 4119 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4120 | { |
| 4121 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 4122 | transformType, transformValues)) |
| 4123 | return false; |
| 4124 | |
| 4125 | switch (coverMode) |
| 4126 | { |
| 4127 | case GL_CONVEX_HULL_CHROMIUM: |
| 4128 | case GL_BOUNDING_BOX_CHROMIUM: |
| 4129 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 4130 | break; |
| 4131 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4132 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 4133 | return false; |
| 4134 | } |
| 4135 | |
| 4136 | return true; |
| 4137 | } |
| 4138 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4139 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
| 4140 | GLuint program, |
| 4141 | GLint location, |
| 4142 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4143 | { |
| 4144 | if (!context->getExtensions().pathRendering) |
| 4145 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4146 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4147 | return false; |
| 4148 | } |
| 4149 | |
| 4150 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 4151 | if (location >= MaxLocation) |
| 4152 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4153 | context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4154 | return false; |
| 4155 | } |
| 4156 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4157 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4158 | if (!programObject) |
| 4159 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4160 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4161 | return false; |
| 4162 | } |
| 4163 | |
| 4164 | if (!name) |
| 4165 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4166 | context->validationError(GL_INVALID_VALUE, kMissingName); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4167 | return false; |
| 4168 | } |
| 4169 | |
| 4170 | if (angle::BeginsWith(name, "gl_")) |
| 4171 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4172 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4173 | return false; |
| 4174 | } |
| 4175 | |
| 4176 | return true; |
| 4177 | } |
| 4178 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 4179 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
| 4180 | GLuint program, |
| 4181 | GLint location, |
| 4182 | GLenum genMode, |
| 4183 | GLint components, |
| 4184 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4185 | { |
| 4186 | if (!context->getExtensions().pathRendering) |
| 4187 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4188 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4189 | return false; |
| 4190 | } |
| 4191 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4192 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4193 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 4194 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4195 | context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4196 | return false; |
| 4197 | } |
| 4198 | |
| 4199 | if (!programObject->isLinked()) |
| 4200 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4201 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4202 | return false; |
| 4203 | } |
| 4204 | |
| 4205 | switch (genMode) |
| 4206 | { |
| 4207 | case GL_NONE: |
| 4208 | if (components != 0) |
| 4209 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4210 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4211 | return false; |
| 4212 | } |
| 4213 | break; |
| 4214 | |
| 4215 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 4216 | case GL_EYE_LINEAR_CHROMIUM: |
| 4217 | case GL_CONSTANT_CHROMIUM: |
| 4218 | if (components < 1 || components > 4) |
| 4219 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4220 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4221 | return false; |
| 4222 | } |
| 4223 | if (!coeffs) |
| 4224 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4225 | context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4226 | return false; |
| 4227 | } |
| 4228 | break; |
| 4229 | |
| 4230 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4231 | context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4232 | return false; |
| 4233 | } |
| 4234 | |
| 4235 | // If the location is -1 then the command is silently ignored |
| 4236 | // and no further validation is needed. |
| 4237 | if (location == -1) |
| 4238 | return true; |
| 4239 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 4240 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4241 | |
| 4242 | if (!binding.valid) |
| 4243 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4244 | context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4245 | return false; |
| 4246 | } |
| 4247 | |
| 4248 | if (binding.type != GL_NONE) |
| 4249 | { |
| 4250 | GLint expectedComponents = 0; |
| 4251 | switch (binding.type) |
| 4252 | { |
| 4253 | case GL_FLOAT: |
| 4254 | expectedComponents = 1; |
| 4255 | break; |
| 4256 | case GL_FLOAT_VEC2: |
| 4257 | expectedComponents = 2; |
| 4258 | break; |
| 4259 | case GL_FLOAT_VEC3: |
| 4260 | expectedComponents = 3; |
| 4261 | break; |
| 4262 | case GL_FLOAT_VEC4: |
| 4263 | expectedComponents = 4; |
| 4264 | break; |
| 4265 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4266 | context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4267 | return false; |
| 4268 | } |
| 4269 | if (expectedComponents != components && genMode != GL_NONE) |
| 4270 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4271 | context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4272 | return false; |
| 4273 | } |
| 4274 | } |
| 4275 | return true; |
| 4276 | } |
| 4277 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4278 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 4279 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4280 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4281 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4282 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4283 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4284 | GLint internalFormat, |
| 4285 | GLenum destType, |
| 4286 | GLboolean unpackFlipY, |
| 4287 | GLboolean unpackPremultiplyAlpha, |
| 4288 | GLboolean unpackUnmultiplyAlpha) |
| 4289 | { |
| 4290 | if (!context->getExtensions().copyTexture) |
| 4291 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4292 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4293 | return false; |
| 4294 | } |
| 4295 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4296 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4297 | if (source == nullptr) |
| 4298 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4299 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4300 | return false; |
| 4301 | } |
| 4302 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4303 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4304 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4305 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4306 | return false; |
| 4307 | } |
| 4308 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4309 | TextureType sourceType = source->getType(); |
| 4310 | ASSERT(sourceType != TextureType::CubeMap); |
| 4311 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4312 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4313 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4314 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4315 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4316 | return false; |
| 4317 | } |
| 4318 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4319 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 4320 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 4321 | if (sourceWidth == 0 || sourceHeight == 0) |
| 4322 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4323 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4324 | return false; |
| 4325 | } |
| 4326 | |
| 4327 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 4328 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4329 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4330 | context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4331 | return false; |
| 4332 | } |
| 4333 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4334 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4335 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4336 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4337 | return false; |
| 4338 | } |
| 4339 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4340 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4341 | if (dest == nullptr) |
| 4342 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4343 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4344 | return false; |
| 4345 | } |
| 4346 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4347 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4348 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4349 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4350 | return false; |
| 4351 | } |
| 4352 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4353 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4354 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4355 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4356 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4357 | return false; |
| 4358 | } |
| 4359 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4360 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 4361 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4362 | return false; |
| 4363 | } |
| 4364 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4365 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4366 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4367 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4368 | return false; |
| 4369 | } |
| 4370 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4371 | if (dest->getImmutableFormat()) |
| 4372 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4373 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4374 | return false; |
| 4375 | } |
| 4376 | |
| 4377 | return true; |
| 4378 | } |
| 4379 | |
| 4380 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 4381 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4382 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4383 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4384 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4385 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4386 | GLint xoffset, |
| 4387 | GLint yoffset, |
| 4388 | GLint x, |
| 4389 | GLint y, |
| 4390 | GLsizei width, |
| 4391 | GLsizei height, |
| 4392 | GLboolean unpackFlipY, |
| 4393 | GLboolean unpackPremultiplyAlpha, |
| 4394 | GLboolean unpackUnmultiplyAlpha) |
| 4395 | { |
| 4396 | if (!context->getExtensions().copyTexture) |
| 4397 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4398 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4399 | return false; |
| 4400 | } |
| 4401 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4402 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4403 | if (source == nullptr) |
| 4404 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4405 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4406 | return false; |
| 4407 | } |
| 4408 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4409 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4410 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4411 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4412 | return false; |
| 4413 | } |
| 4414 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4415 | TextureType sourceType = source->getType(); |
| 4416 | ASSERT(sourceType != TextureType::CubeMap); |
| 4417 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4418 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4419 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4420 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4421 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4422 | return false; |
| 4423 | } |
| 4424 | |
| 4425 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4426 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4427 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4428 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4429 | return false; |
| 4430 | } |
| 4431 | |
| 4432 | if (x < 0 || y < 0) |
| 4433 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4434 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4435 | return false; |
| 4436 | } |
| 4437 | |
| 4438 | if (width < 0 || height < 0) |
| 4439 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4440 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4441 | return false; |
| 4442 | } |
| 4443 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4444 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4445 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4446 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4447 | context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4448 | return false; |
| 4449 | } |
| 4450 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4451 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4452 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4453 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4454 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4455 | return false; |
| 4456 | } |
| 4457 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4458 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4459 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4460 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4461 | return false; |
| 4462 | } |
| 4463 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4464 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4465 | if (dest == nullptr) |
| 4466 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4467 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4468 | return false; |
| 4469 | } |
| 4470 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4471 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4472 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4473 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4474 | return false; |
| 4475 | } |
| 4476 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4477 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4478 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4479 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4480 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4481 | return false; |
| 4482 | } |
| 4483 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4484 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4485 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4486 | context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4487 | return false; |
| 4488 | } |
| 4489 | |
| 4490 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4491 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4492 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4493 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4494 | return false; |
| 4495 | } |
| 4496 | |
| 4497 | if (xoffset < 0 || yoffset < 0) |
| 4498 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4499 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4500 | return false; |
| 4501 | } |
| 4502 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4503 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4504 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4505 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4506 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4507 | return false; |
| 4508 | } |
| 4509 | |
| 4510 | return true; |
| 4511 | } |
| 4512 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4513 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 4514 | { |
| 4515 | if (!context->getExtensions().copyCompressedTexture) |
| 4516 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4517 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4518 | return false; |
| 4519 | } |
| 4520 | |
| 4521 | const gl::Texture *source = context->getTexture(sourceId); |
| 4522 | if (source == nullptr) |
| 4523 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4524 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4525 | return false; |
| 4526 | } |
| 4527 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4528 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4529 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4530 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4531 | return false; |
| 4532 | } |
| 4533 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4534 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4535 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4536 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4537 | context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4538 | return false; |
| 4539 | } |
| 4540 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4541 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4542 | if (!sourceFormat.info->compressed) |
| 4543 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4544 | context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4545 | return false; |
| 4546 | } |
| 4547 | |
| 4548 | const gl::Texture *dest = context->getTexture(destId); |
| 4549 | if (dest == nullptr) |
| 4550 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4551 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4552 | return false; |
| 4553 | } |
| 4554 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4555 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4556 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4557 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4558 | return false; |
| 4559 | } |
| 4560 | |
| 4561 | if (dest->getImmutableFormat()) |
| 4562 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4563 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4564 | return false; |
| 4565 | } |
| 4566 | |
| 4567 | return true; |
| 4568 | } |
| 4569 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4570 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4571 | { |
| 4572 | switch (type) |
| 4573 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4574 | case ShaderType::Vertex: |
| 4575 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4576 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4577 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4578 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4579 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4580 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4581 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4582 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4583 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4584 | break; |
| 4585 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4586 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4587 | if (!context->getExtensions().geometryShader) |
| 4588 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4589 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4590 | return false; |
| 4591 | } |
| 4592 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4593 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4594 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4595 | return false; |
| 4596 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4597 | |
| 4598 | return true; |
| 4599 | } |
| 4600 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4601 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4602 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4603 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4604 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4605 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4606 | { |
| 4607 | if (size < 0) |
| 4608 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4609 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4610 | return false; |
| 4611 | } |
| 4612 | |
| 4613 | switch (usage) |
| 4614 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4615 | case BufferUsage::StreamDraw: |
| 4616 | case BufferUsage::StaticDraw: |
| 4617 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4618 | break; |
| 4619 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4620 | case BufferUsage::StreamRead: |
| 4621 | case BufferUsage::StaticRead: |
| 4622 | case BufferUsage::DynamicRead: |
| 4623 | case BufferUsage::StreamCopy: |
| 4624 | case BufferUsage::StaticCopy: |
| 4625 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4626 | if (context->getClientMajorVersion() < 3) |
| 4627 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4628 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4629 | return false; |
| 4630 | } |
| 4631 | break; |
| 4632 | |
| 4633 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4634 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4635 | return false; |
| 4636 | } |
| 4637 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4638 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4639 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4640 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4641 | return false; |
| 4642 | } |
| 4643 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4644 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4645 | |
| 4646 | if (!buffer) |
| 4647 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4648 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4649 | return false; |
| 4650 | } |
| 4651 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4652 | if (context->getExtensions().webglCompatibility && |
| 4653 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4654 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4655 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4656 | return false; |
| 4657 | } |
| 4658 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4659 | return true; |
| 4660 | } |
| 4661 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4662 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4663 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4664 | GLintptr offset, |
| 4665 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4666 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4667 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4668 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4669 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4670 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4671 | return false; |
| 4672 | } |
| 4673 | |
| 4674 | if (offset < 0) |
| 4675 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4676 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4677 | return false; |
| 4678 | } |
| 4679 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4680 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4681 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4682 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4683 | return false; |
| 4684 | } |
| 4685 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4686 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4687 | |
| 4688 | if (!buffer) |
| 4689 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4690 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4691 | return false; |
| 4692 | } |
| 4693 | |
| 4694 | if (buffer->isMapped()) |
| 4695 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4696 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4697 | return false; |
| 4698 | } |
| 4699 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4700 | if (context->getExtensions().webglCompatibility && |
| 4701 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4702 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4703 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4704 | return false; |
| 4705 | } |
| 4706 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4707 | // Check for possible overflow of size + offset |
| 4708 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4709 | checkedSize += offset; |
| 4710 | if (!checkedSize.IsValid()) |
| 4711 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4712 | context->validationError(GL_INVALID_VALUE, kParamOverflow); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4713 | return false; |
| 4714 | } |
| 4715 | |
| 4716 | if (size + offset > buffer->getSize()) |
| 4717 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4718 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4719 | return false; |
| 4720 | } |
| 4721 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4722 | return true; |
| 4723 | } |
| 4724 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4725 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4726 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4727 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4728 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4729 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4730 | return false; |
| 4731 | } |
| 4732 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4733 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4734 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4735 | context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4736 | return false; |
| 4737 | } |
| 4738 | |
| 4739 | return true; |
| 4740 | } |
| 4741 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4742 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4743 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4744 | if (context->getClientMajorVersion() < 2) |
| 4745 | { |
| 4746 | return ValidateMultitextureUnit(context, texture); |
| 4747 | } |
| 4748 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4749 | if (texture < GL_TEXTURE0 || |
| 4750 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4751 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4752 | context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4753 | return false; |
| 4754 | } |
| 4755 | |
| 4756 | return true; |
| 4757 | } |
| 4758 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4759 | bool ValidateAttachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4760 | { |
| 4761 | Program *programObject = GetValidProgram(context, program); |
| 4762 | if (!programObject) |
| 4763 | { |
| 4764 | return false; |
| 4765 | } |
| 4766 | |
| 4767 | Shader *shaderObject = GetValidShader(context, shader); |
| 4768 | if (!shaderObject) |
| 4769 | { |
| 4770 | return false; |
| 4771 | } |
| 4772 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4773 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4774 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4775 | context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4776 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | return true; |
| 4780 | } |
| 4781 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4782 | bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4783 | { |
| 4784 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4785 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4786 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4787 | return false; |
| 4788 | } |
| 4789 | |
| 4790 | if (strncmp(name, "gl_", 3) == 0) |
| 4791 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4792 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4793 | return false; |
| 4794 | } |
| 4795 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4796 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4797 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4798 | const size_t length = strlen(name); |
| 4799 | |
| 4800 | if (!IsValidESSLString(name, length)) |
| 4801 | { |
| 4802 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4803 | // for shader-related entry points |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4804 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4805 | return false; |
| 4806 | } |
| 4807 | |
| 4808 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4809 | { |
| 4810 | return false; |
| 4811 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4812 | } |
| 4813 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4814 | return GetValidProgram(context, program) != nullptr; |
| 4815 | } |
| 4816 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4817 | bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4818 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4819 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4820 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4821 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4822 | return false; |
| 4823 | } |
| 4824 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4825 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4826 | !context->isFramebufferGenerated(framebuffer)) |
| 4827 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4828 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4829 | return false; |
| 4830 | } |
| 4831 | |
| 4832 | return true; |
| 4833 | } |
| 4834 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4835 | bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4836 | { |
| 4837 | if (target != GL_RENDERBUFFER) |
| 4838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4839 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4840 | return false; |
| 4841 | } |
| 4842 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4843 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4844 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4845 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4846 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4847 | return false; |
| 4848 | } |
| 4849 | |
| 4850 | return true; |
| 4851 | } |
| 4852 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4853 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4854 | { |
| 4855 | switch (mode) |
| 4856 | { |
| 4857 | case GL_FUNC_ADD: |
| 4858 | case GL_FUNC_SUBTRACT: |
| 4859 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4860 | return true; |
| 4861 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4862 | case GL_MIN: |
| 4863 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4864 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4865 | |
| 4866 | default: |
| 4867 | return false; |
| 4868 | } |
| 4869 | } |
| 4870 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4871 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4872 | { |
| 4873 | return true; |
| 4874 | } |
| 4875 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4876 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4877 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4878 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4879 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4880 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4881 | return false; |
| 4882 | } |
| 4883 | |
| 4884 | return true; |
| 4885 | } |
| 4886 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4887 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4888 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4889 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4890 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4891 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4892 | return false; |
| 4893 | } |
| 4894 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4895 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4896 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4897 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4898 | return false; |
| 4899 | } |
| 4900 | |
| 4901 | return true; |
| 4902 | } |
| 4903 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4904 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4905 | { |
| 4906 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 4907 | } |
| 4908 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4909 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4910 | GLenum srcRGB, |
| 4911 | GLenum dstRGB, |
| 4912 | GLenum srcAlpha, |
| 4913 | GLenum dstAlpha) |
| 4914 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4915 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4916 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4917 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4918 | return false; |
| 4919 | } |
| 4920 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4921 | if (!ValidDstBlendFunc(context, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4922 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4923 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4924 | return false; |
| 4925 | } |
| 4926 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4927 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4928 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4929 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4930 | return false; |
| 4931 | } |
| 4932 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4933 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4934 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4935 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4936 | return false; |
| 4937 | } |
| 4938 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4939 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 4940 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4941 | { |
| 4942 | bool constantColorUsed = |
| 4943 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 4944 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 4945 | |
| 4946 | bool constantAlphaUsed = |
| 4947 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 4948 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 4949 | |
| 4950 | if (constantColorUsed && constantAlphaUsed) |
| 4951 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4952 | if (context->getExtensions().webglCompatibility) |
| 4953 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4954 | context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor); |
| 4955 | return false; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4956 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4957 | |
| 4958 | WARN() << kConstantColorAlphaLimitation; |
| 4959 | context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4960 | return false; |
| 4961 | } |
| 4962 | } |
| 4963 | |
| 4964 | return true; |
| 4965 | } |
| 4966 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4967 | bool ValidateGetString(Context *context, GLenum name) |
| 4968 | { |
| 4969 | switch (name) |
| 4970 | { |
| 4971 | case GL_VENDOR: |
| 4972 | case GL_RENDERER: |
| 4973 | case GL_VERSION: |
| 4974 | case GL_SHADING_LANGUAGE_VERSION: |
| 4975 | case GL_EXTENSIONS: |
| 4976 | break; |
| 4977 | |
| 4978 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 4979 | if (!context->getExtensions().requestExtension) |
| 4980 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4981 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4982 | return false; |
| 4983 | } |
| 4984 | break; |
| 4985 | |
| 4986 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4987 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4988 | return false; |
| 4989 | } |
| 4990 | |
| 4991 | return true; |
| 4992 | } |
| 4993 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4994 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4995 | { |
| 4996 | if (width <= 0.0f || isNaN(width)) |
| 4997 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4998 | context->validationError(GL_INVALID_VALUE, kInvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4999 | return false; |
| 5000 | } |
| 5001 | |
| 5002 | return true; |
| 5003 | } |
| 5004 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5005 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5006 | { |
| 5007 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 5008 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5009 | context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 5010 | return false; |
| 5011 | } |
| 5012 | |
| 5013 | return true; |
| 5014 | } |
| 5015 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5016 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5017 | GLenum target, |
| 5018 | GLenum internalformat, |
| 5019 | GLsizei width, |
| 5020 | GLsizei height) |
| 5021 | { |
| 5022 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 5023 | height); |
| 5024 | } |
| 5025 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5026 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5027 | GLenum target, |
| 5028 | GLsizei samples, |
| 5029 | GLenum internalformat, |
| 5030 | GLsizei width, |
| 5031 | GLsizei height) |
| 5032 | { |
| 5033 | if (!context->getExtensions().framebufferMultisample) |
| 5034 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5035 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5036 | return false; |
| 5037 | } |
| 5038 | |
| 5039 | // 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] | 5040 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5041 | // generated. |
| 5042 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 5043 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5044 | context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5045 | return false; |
| 5046 | } |
| 5047 | |
| 5048 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 5049 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 5050 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 5051 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 5052 | if (context->getClientMajorVersion() >= 3) |
| 5053 | { |
| 5054 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 5055 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 5056 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5057 | context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 5058 | return false; |
| 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 5063 | width, height); |
| 5064 | } |
| 5065 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5066 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5067 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5068 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5069 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5070 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5071 | return false; |
| 5072 | } |
| 5073 | |
| 5074 | return true; |
| 5075 | } |
| 5076 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5077 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5078 | { |
| 5079 | return true; |
| 5080 | } |
| 5081 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5082 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5083 | { |
| 5084 | return true; |
| 5085 | } |
| 5086 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5087 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5088 | { |
| 5089 | return true; |
| 5090 | } |
| 5091 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5092 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5093 | GLboolean red, |
| 5094 | GLboolean green, |
| 5095 | GLboolean blue, |
| 5096 | GLboolean alpha) |
| 5097 | { |
| 5098 | return true; |
| 5099 | } |
| 5100 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5101 | bool ValidateCompileShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5102 | { |
| 5103 | return true; |
| 5104 | } |
| 5105 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5106 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5107 | { |
| 5108 | return true; |
| 5109 | } |
| 5110 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5111 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5112 | { |
| 5113 | switch (mode) |
| 5114 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 5115 | case CullFaceMode::Front: |
| 5116 | case CullFaceMode::Back: |
| 5117 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5118 | break; |
| 5119 | |
| 5120 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5121 | context->validationError(GL_INVALID_ENUM, kInvalidCullMode); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5122 | return false; |
| 5123 | } |
| 5124 | |
| 5125 | return true; |
| 5126 | } |
| 5127 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5128 | bool ValidateDeleteProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5129 | { |
| 5130 | if (program == 0) |
| 5131 | { |
| 5132 | return false; |
| 5133 | } |
| 5134 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5135 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5136 | { |
| 5137 | if (context->getShader(program)) |
| 5138 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5139 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5140 | return false; |
| 5141 | } |
| 5142 | else |
| 5143 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5144 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5145 | return false; |
| 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | return true; |
| 5150 | } |
| 5151 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5152 | bool ValidateDeleteShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5153 | { |
| 5154 | if (shader == 0) |
| 5155 | { |
| 5156 | return false; |
| 5157 | } |
| 5158 | |
| 5159 | if (!context->getShader(shader)) |
| 5160 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5161 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5162 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5163 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5164 | return false; |
| 5165 | } |
| 5166 | else |
| 5167 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5168 | context->validationError(GL_INVALID_VALUE, kExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5169 | return false; |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | return true; |
| 5174 | } |
| 5175 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5176 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5177 | { |
| 5178 | switch (func) |
| 5179 | { |
| 5180 | case GL_NEVER: |
| 5181 | case GL_ALWAYS: |
| 5182 | case GL_LESS: |
| 5183 | case GL_LEQUAL: |
| 5184 | case GL_EQUAL: |
| 5185 | case GL_GREATER: |
| 5186 | case GL_GEQUAL: |
| 5187 | case GL_NOTEQUAL: |
| 5188 | break; |
| 5189 | |
| 5190 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5191 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5192 | return false; |
| 5193 | } |
| 5194 | |
| 5195 | return true; |
| 5196 | } |
| 5197 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5198 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5199 | { |
| 5200 | return true; |
| 5201 | } |
| 5202 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5203 | bool ValidateDetachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5204 | { |
| 5205 | Program *programObject = GetValidProgram(context, program); |
| 5206 | if (!programObject) |
| 5207 | { |
| 5208 | return false; |
| 5209 | } |
| 5210 | |
| 5211 | Shader *shaderObject = GetValidShader(context, shader); |
| 5212 | if (!shaderObject) |
| 5213 | { |
| 5214 | return false; |
| 5215 | } |
| 5216 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5217 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5218 | if (attachedShader != shaderObject) |
| 5219 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5220 | context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5221 | return false; |
| 5222 | } |
| 5223 | |
| 5224 | return true; |
| 5225 | } |
| 5226 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5227 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5228 | { |
| 5229 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5230 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5231 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5232 | return false; |
| 5233 | } |
| 5234 | |
| 5235 | return true; |
| 5236 | } |
| 5237 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5238 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5239 | { |
| 5240 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5241 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5242 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5243 | return false; |
| 5244 | } |
| 5245 | |
| 5246 | return true; |
| 5247 | } |
| 5248 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5249 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5250 | { |
| 5251 | return true; |
| 5252 | } |
| 5253 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5254 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5255 | { |
| 5256 | return true; |
| 5257 | } |
| 5258 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5259 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5260 | { |
| 5261 | switch (mode) |
| 5262 | { |
| 5263 | case GL_CW: |
| 5264 | case GL_CCW: |
| 5265 | break; |
| 5266 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5267 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5268 | return false; |
| 5269 | } |
| 5270 | |
| 5271 | return true; |
| 5272 | } |
| 5273 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5274 | bool ValidateGetActiveAttrib(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5275 | GLuint program, |
| 5276 | GLuint index, |
| 5277 | GLsizei bufsize, |
| 5278 | GLsizei *length, |
| 5279 | GLint *size, |
| 5280 | GLenum *type, |
| 5281 | GLchar *name) |
| 5282 | { |
| 5283 | if (bufsize < 0) |
| 5284 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5285 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5286 | return false; |
| 5287 | } |
| 5288 | |
| 5289 | Program *programObject = GetValidProgram(context, program); |
| 5290 | |
| 5291 | if (!programObject) |
| 5292 | { |
| 5293 | return false; |
| 5294 | } |
| 5295 | |
| 5296 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 5297 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5298 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5299 | return false; |
| 5300 | } |
| 5301 | |
| 5302 | return true; |
| 5303 | } |
| 5304 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5305 | bool ValidateGetActiveUniform(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5306 | GLuint program, |
| 5307 | GLuint index, |
| 5308 | GLsizei bufsize, |
| 5309 | GLsizei *length, |
| 5310 | GLint *size, |
| 5311 | GLenum *type, |
| 5312 | GLchar *name) |
| 5313 | { |
| 5314 | if (bufsize < 0) |
| 5315 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5316 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5317 | return false; |
| 5318 | } |
| 5319 | |
| 5320 | Program *programObject = GetValidProgram(context, program); |
| 5321 | |
| 5322 | if (!programObject) |
| 5323 | { |
| 5324 | return false; |
| 5325 | } |
| 5326 | |
| 5327 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 5328 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5329 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5330 | return false; |
| 5331 | } |
| 5332 | |
| 5333 | return true; |
| 5334 | } |
| 5335 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5336 | bool ValidateGetAttachedShaders(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5337 | GLuint program, |
| 5338 | GLsizei maxcount, |
| 5339 | GLsizei *count, |
| 5340 | GLuint *shaders) |
| 5341 | { |
| 5342 | if (maxcount < 0) |
| 5343 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5344 | context->validationError(GL_INVALID_VALUE, kNegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5345 | return false; |
| 5346 | } |
| 5347 | |
| 5348 | Program *programObject = GetValidProgram(context, program); |
| 5349 | |
| 5350 | if (!programObject) |
| 5351 | { |
| 5352 | return false; |
| 5353 | } |
| 5354 | |
| 5355 | return true; |
| 5356 | } |
| 5357 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5358 | bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5359 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5360 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5361 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5362 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5363 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5364 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5365 | return false; |
| 5366 | } |
| 5367 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5368 | Program *programObject = GetValidProgram(context, program); |
| 5369 | |
| 5370 | if (!programObject) |
| 5371 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5372 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5373 | return false; |
| 5374 | } |
| 5375 | |
| 5376 | if (!programObject->isLinked()) |
| 5377 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5378 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5379 | return false; |
| 5380 | } |
| 5381 | |
| 5382 | return true; |
| 5383 | } |
| 5384 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5385 | bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5386 | { |
| 5387 | GLenum nativeType; |
| 5388 | unsigned int numParams = 0; |
| 5389 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5390 | } |
| 5391 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5392 | bool ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5393 | { |
| 5394 | return true; |
| 5395 | } |
| 5396 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5397 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5398 | { |
| 5399 | GLenum nativeType; |
| 5400 | unsigned int numParams = 0; |
| 5401 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5402 | } |
| 5403 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5404 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5405 | { |
| 5406 | GLenum nativeType; |
| 5407 | unsigned int numParams = 0; |
| 5408 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5409 | } |
| 5410 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5411 | bool ValidateGetProgramInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5412 | GLuint program, |
| 5413 | GLsizei bufsize, |
| 5414 | GLsizei *length, |
| 5415 | GLchar *infolog) |
| 5416 | { |
| 5417 | if (bufsize < 0) |
| 5418 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5419 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5420 | return false; |
| 5421 | } |
| 5422 | |
| 5423 | Program *programObject = GetValidProgram(context, program); |
| 5424 | if (!programObject) |
| 5425 | { |
| 5426 | return false; |
| 5427 | } |
| 5428 | |
| 5429 | return true; |
| 5430 | } |
| 5431 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5432 | bool ValidateGetShaderInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5433 | GLuint shader, |
| 5434 | GLsizei bufsize, |
| 5435 | GLsizei *length, |
| 5436 | GLchar *infolog) |
| 5437 | { |
| 5438 | if (bufsize < 0) |
| 5439 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5440 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5441 | return false; |
| 5442 | } |
| 5443 | |
| 5444 | Shader *shaderObject = GetValidShader(context, shader); |
| 5445 | if (!shaderObject) |
| 5446 | { |
| 5447 | return false; |
| 5448 | } |
| 5449 | |
| 5450 | return true; |
| 5451 | } |
| 5452 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5453 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5454 | GLenum shadertype, |
| 5455 | GLenum precisiontype, |
| 5456 | GLint *range, |
| 5457 | GLint *precision) |
| 5458 | { |
| 5459 | switch (shadertype) |
| 5460 | { |
| 5461 | case GL_VERTEX_SHADER: |
| 5462 | case GL_FRAGMENT_SHADER: |
| 5463 | break; |
| 5464 | case GL_COMPUTE_SHADER: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5465 | context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5466 | return false; |
| 5467 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5468 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5469 | return false; |
| 5470 | } |
| 5471 | |
| 5472 | switch (precisiontype) |
| 5473 | { |
| 5474 | case GL_LOW_FLOAT: |
| 5475 | case GL_MEDIUM_FLOAT: |
| 5476 | case GL_HIGH_FLOAT: |
| 5477 | case GL_LOW_INT: |
| 5478 | case GL_MEDIUM_INT: |
| 5479 | case GL_HIGH_INT: |
| 5480 | break; |
| 5481 | |
| 5482 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5483 | context->validationError(GL_INVALID_ENUM, kInvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5484 | return false; |
| 5485 | } |
| 5486 | |
| 5487 | return true; |
| 5488 | } |
| 5489 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5490 | bool ValidateGetShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5491 | GLuint shader, |
| 5492 | GLsizei bufsize, |
| 5493 | GLsizei *length, |
| 5494 | GLchar *source) |
| 5495 | { |
| 5496 | if (bufsize < 0) |
| 5497 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5498 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5499 | return false; |
| 5500 | } |
| 5501 | |
| 5502 | Shader *shaderObject = GetValidShader(context, shader); |
| 5503 | if (!shaderObject) |
| 5504 | { |
| 5505 | return false; |
| 5506 | } |
| 5507 | |
| 5508 | return true; |
| 5509 | } |
| 5510 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5511 | bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5512 | { |
| 5513 | if (strstr(name, "gl_") == name) |
| 5514 | { |
| 5515 | return false; |
| 5516 | } |
| 5517 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5518 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5519 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5520 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5521 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5522 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5523 | return false; |
| 5524 | } |
| 5525 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5526 | Program *programObject = GetValidProgram(context, program); |
| 5527 | |
| 5528 | if (!programObject) |
| 5529 | { |
| 5530 | return false; |
| 5531 | } |
| 5532 | |
| 5533 | if (!programObject->isLinked()) |
| 5534 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5535 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5536 | return false; |
| 5537 | } |
| 5538 | |
| 5539 | return true; |
| 5540 | } |
| 5541 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5542 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5543 | { |
| 5544 | switch (mode) |
| 5545 | { |
| 5546 | case GL_FASTEST: |
| 5547 | case GL_NICEST: |
| 5548 | case GL_DONT_CARE: |
| 5549 | break; |
| 5550 | |
| 5551 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5552 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5553 | return false; |
| 5554 | } |
| 5555 | |
| 5556 | switch (target) |
| 5557 | { |
| 5558 | case GL_GENERATE_MIPMAP_HINT: |
| 5559 | break; |
| 5560 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5561 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5562 | if (context->getClientVersion() < ES_3_0 && |
| 5563 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5564 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5565 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5566 | return false; |
| 5567 | } |
| 5568 | break; |
| 5569 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5570 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5571 | case GL_POINT_SMOOTH_HINT: |
| 5572 | case GL_LINE_SMOOTH_HINT: |
| 5573 | case GL_FOG_HINT: |
| 5574 | if (context->getClientMajorVersion() >= 2) |
| 5575 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5576 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5577 | return false; |
| 5578 | } |
| 5579 | break; |
| 5580 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5581 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5582 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5583 | return false; |
| 5584 | } |
| 5585 | |
| 5586 | return true; |
| 5587 | } |
| 5588 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5589 | bool ValidateIsBuffer(Context *context, GLuint buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5590 | { |
| 5591 | return true; |
| 5592 | } |
| 5593 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5594 | bool ValidateIsFramebuffer(Context *context, GLuint framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5595 | { |
| 5596 | return true; |
| 5597 | } |
| 5598 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5599 | bool ValidateIsProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5600 | { |
| 5601 | return true; |
| 5602 | } |
| 5603 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5604 | bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5605 | { |
| 5606 | return true; |
| 5607 | } |
| 5608 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5609 | bool ValidateIsShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5610 | { |
| 5611 | return true; |
| 5612 | } |
| 5613 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5614 | bool ValidateIsTexture(Context *context, GLuint texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5615 | { |
| 5616 | return true; |
| 5617 | } |
| 5618 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5619 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5620 | { |
| 5621 | if (context->getClientMajorVersion() < 3) |
| 5622 | { |
| 5623 | switch (pname) |
| 5624 | { |
| 5625 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5626 | case GL_UNPACK_SKIP_IMAGES: |
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 | case GL_UNPACK_ROW_LENGTH: |
| 5631 | case GL_UNPACK_SKIP_ROWS: |
| 5632 | case GL_UNPACK_SKIP_PIXELS: |
| 5633 | if (!context->getExtensions().unpackSubimage) |
| 5634 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5635 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5636 | return false; |
| 5637 | } |
| 5638 | break; |
| 5639 | |
| 5640 | case GL_PACK_ROW_LENGTH: |
| 5641 | case GL_PACK_SKIP_ROWS: |
| 5642 | case GL_PACK_SKIP_PIXELS: |
| 5643 | if (!context->getExtensions().packSubimage) |
| 5644 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5645 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5646 | return false; |
| 5647 | } |
| 5648 | break; |
| 5649 | } |
| 5650 | } |
| 5651 | |
| 5652 | if (param < 0) |
| 5653 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5654 | context->validationError(GL_INVALID_VALUE, kNegativeParam); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5655 | return false; |
| 5656 | } |
| 5657 | |
| 5658 | switch (pname) |
| 5659 | { |
| 5660 | case GL_UNPACK_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_ALIGNMENT: |
| 5669 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5670 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5671 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5672 | return false; |
| 5673 | } |
| 5674 | break; |
| 5675 | |
| 5676 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5677 | if (!context->getExtensions().packReverseRowOrder) |
| 5678 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5679 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5680 | } |
| 5681 | break; |
| 5682 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5683 | case GL_UNPACK_ROW_LENGTH: |
| 5684 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5685 | case GL_UNPACK_SKIP_IMAGES: |
| 5686 | case GL_UNPACK_SKIP_ROWS: |
| 5687 | case GL_UNPACK_SKIP_PIXELS: |
| 5688 | case GL_PACK_ROW_LENGTH: |
| 5689 | case GL_PACK_SKIP_ROWS: |
| 5690 | case GL_PACK_SKIP_PIXELS: |
| 5691 | break; |
| 5692 | |
| 5693 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5694 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5695 | return false; |
| 5696 | } |
| 5697 | |
| 5698 | return true; |
| 5699 | } |
| 5700 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5701 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5702 | { |
| 5703 | return true; |
| 5704 | } |
| 5705 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5706 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5707 | { |
| 5708 | return true; |
| 5709 | } |
| 5710 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5711 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5712 | { |
| 5713 | return true; |
| 5714 | } |
| 5715 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5716 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5717 | { |
| 5718 | if (width < 0 || height < 0) |
| 5719 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5720 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5721 | return false; |
| 5722 | } |
| 5723 | |
| 5724 | return true; |
| 5725 | } |
| 5726 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5727 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5728 | GLsizei n, |
| 5729 | const GLuint *shaders, |
| 5730 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5731 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5732 | GLsizei length) |
| 5733 | { |
| 5734 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5735 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5736 | shaderBinaryFormats.end()) |
| 5737 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5738 | context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5739 | return false; |
| 5740 | } |
| 5741 | |
| 5742 | return true; |
| 5743 | } |
| 5744 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5745 | bool ValidateShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5746 | GLuint shader, |
| 5747 | GLsizei count, |
| 5748 | const GLchar *const *string, |
| 5749 | const GLint *length) |
| 5750 | { |
| 5751 | if (count < 0) |
| 5752 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5753 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5754 | return false; |
| 5755 | } |
| 5756 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5757 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5758 | // shader-related entry points |
| 5759 | if (context->getExtensions().webglCompatibility) |
| 5760 | { |
| 5761 | for (GLsizei i = 0; i < count; i++) |
| 5762 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5763 | size_t len = |
| 5764 | (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] | 5765 | |
| 5766 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5767 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5768 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5769 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5770 | context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5771 | return false; |
| 5772 | } |
| 5773 | } |
| 5774 | } |
| 5775 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5776 | Shader *shaderObject = GetValidShader(context, shader); |
| 5777 | if (!shaderObject) |
| 5778 | { |
| 5779 | return false; |
| 5780 | } |
| 5781 | |
| 5782 | return true; |
| 5783 | } |
| 5784 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5785 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5786 | { |
| 5787 | if (!IsValidStencilFunc(func)) |
| 5788 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5789 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5790 | return false; |
| 5791 | } |
| 5792 | |
| 5793 | return true; |
| 5794 | } |
| 5795 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5796 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5797 | { |
| 5798 | if (!IsValidStencilFace(face)) |
| 5799 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5800 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5801 | return false; |
| 5802 | } |
| 5803 | |
| 5804 | if (!IsValidStencilFunc(func)) |
| 5805 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5806 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5807 | return false; |
| 5808 | } |
| 5809 | |
| 5810 | return true; |
| 5811 | } |
| 5812 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5813 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5814 | { |
| 5815 | return true; |
| 5816 | } |
| 5817 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5818 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5819 | { |
| 5820 | if (!IsValidStencilFace(face)) |
| 5821 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5822 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5823 | return false; |
| 5824 | } |
| 5825 | |
| 5826 | return true; |
| 5827 | } |
| 5828 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5829 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5830 | { |
| 5831 | if (!IsValidStencilOp(fail)) |
| 5832 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5833 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5834 | return false; |
| 5835 | } |
| 5836 | |
| 5837 | if (!IsValidStencilOp(zfail)) |
| 5838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5839 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5840 | return false; |
| 5841 | } |
| 5842 | |
| 5843 | if (!IsValidStencilOp(zpass)) |
| 5844 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5845 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5846 | return false; |
| 5847 | } |
| 5848 | |
| 5849 | return true; |
| 5850 | } |
| 5851 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5852 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5853 | GLenum face, |
| 5854 | GLenum fail, |
| 5855 | GLenum zfail, |
| 5856 | GLenum zpass) |
| 5857 | { |
| 5858 | if (!IsValidStencilFace(face)) |
| 5859 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5860 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5861 | return false; |
| 5862 | } |
| 5863 | |
| 5864 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5865 | } |
| 5866 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5867 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5868 | { |
| 5869 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5870 | } |
| 5871 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5872 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5873 | { |
| 5874 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5875 | } |
| 5876 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5877 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5878 | { |
| 5879 | return ValidateUniform1iv(context, location, 1, &x); |
| 5880 | } |
| 5881 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5882 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5883 | { |
| 5884 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 5885 | } |
| 5886 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5887 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5888 | { |
| 5889 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 5890 | } |
| 5891 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5892 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5893 | { |
| 5894 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 5895 | } |
| 5896 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5897 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5898 | { |
| 5899 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 5900 | } |
| 5901 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5902 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5903 | { |
| 5904 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 5905 | } |
| 5906 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5907 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5908 | { |
| 5909 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 5910 | } |
| 5911 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5912 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5913 | { |
| 5914 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 5915 | } |
| 5916 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5917 | 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] | 5918 | { |
| 5919 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 5920 | } |
| 5921 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5922 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5923 | { |
| 5924 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 5925 | } |
| 5926 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5927 | 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] | 5928 | { |
| 5929 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 5930 | } |
| 5931 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5932 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5933 | { |
| 5934 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 5935 | } |
| 5936 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5937 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5938 | GLint location, |
| 5939 | GLsizei count, |
| 5940 | GLboolean transpose, |
| 5941 | const GLfloat *value) |
| 5942 | { |
| 5943 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 5944 | } |
| 5945 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5946 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5947 | GLint location, |
| 5948 | GLsizei count, |
| 5949 | GLboolean transpose, |
| 5950 | const GLfloat *value) |
| 5951 | { |
| 5952 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 5953 | } |
| 5954 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5955 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5956 | GLint location, |
| 5957 | GLsizei count, |
| 5958 | GLboolean transpose, |
| 5959 | const GLfloat *value) |
| 5960 | { |
| 5961 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 5962 | } |
| 5963 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5964 | bool ValidateValidateProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5965 | { |
| 5966 | Program *programObject = GetValidProgram(context, program); |
| 5967 | |
| 5968 | if (!programObject) |
| 5969 | { |
| 5970 | return false; |
| 5971 | } |
| 5972 | |
| 5973 | return true; |
| 5974 | } |
| 5975 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5976 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5977 | { |
| 5978 | return ValidateVertexAttribIndex(context, index); |
| 5979 | } |
| 5980 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5981 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5982 | { |
| 5983 | return ValidateVertexAttribIndex(context, index); |
| 5984 | } |
| 5985 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5986 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5987 | { |
| 5988 | return ValidateVertexAttribIndex(context, index); |
| 5989 | } |
| 5990 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5991 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5992 | { |
| 5993 | return ValidateVertexAttribIndex(context, index); |
| 5994 | } |
| 5995 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5996 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5997 | { |
| 5998 | return ValidateVertexAttribIndex(context, index); |
| 5999 | } |
| 6000 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6001 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6002 | { |
| 6003 | return ValidateVertexAttribIndex(context, index); |
| 6004 | } |
| 6005 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6006 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6007 | GLuint index, |
| 6008 | GLfloat x, |
| 6009 | GLfloat y, |
| 6010 | GLfloat z, |
| 6011 | GLfloat w) |
| 6012 | { |
| 6013 | return ValidateVertexAttribIndex(context, index); |
| 6014 | } |
| 6015 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6016 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6017 | { |
| 6018 | return ValidateVertexAttribIndex(context, index); |
| 6019 | } |
| 6020 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6021 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6022 | { |
| 6023 | if (width < 0 || height < 0) |
| 6024 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6025 | context->validationError(GL_INVALID_VALUE, kViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 6026 | return false; |
| 6027 | } |
| 6028 | |
| 6029 | return true; |
| 6030 | } |
| 6031 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 6032 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6033 | GLenum target, |
| 6034 | GLenum attachment, |
| 6035 | GLenum pname, |
| 6036 | GLint *params) |
| 6037 | { |
| 6038 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 6039 | nullptr); |
| 6040 | } |
| 6041 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6042 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6043 | { |
| 6044 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 6045 | } |
| 6046 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6047 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6048 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6049 | GLint level, |
| 6050 | GLenum internalformat, |
| 6051 | GLint x, |
| 6052 | GLint y, |
| 6053 | GLsizei width, |
| 6054 | GLsizei height, |
| 6055 | GLint border) |
| 6056 | { |
| 6057 | if (context->getClientMajorVersion() < 3) |
| 6058 | { |
| 6059 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 6060 | 0, x, y, width, height, border); |
| 6061 | } |
| 6062 | |
| 6063 | ASSERT(context->getClientMajorVersion() == 3); |
| 6064 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 6065 | 0, x, y, width, height, border); |
| 6066 | } |
| 6067 | |
| 6068 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6069 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6070 | GLint level, |
| 6071 | GLint xoffset, |
| 6072 | GLint yoffset, |
| 6073 | GLint x, |
| 6074 | GLint y, |
| 6075 | GLsizei width, |
| 6076 | GLsizei height) |
| 6077 | { |
| 6078 | if (context->getClientMajorVersion() < 3) |
| 6079 | { |
| 6080 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 6081 | yoffset, x, y, width, height, 0); |
| 6082 | } |
| 6083 | |
| 6084 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 6085 | yoffset, 0, x, y, width, height, 0); |
| 6086 | } |
| 6087 | |
| 6088 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 6089 | { |
| 6090 | return ValidateGenOrDelete(context, n); |
| 6091 | } |
| 6092 | |
| 6093 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 6094 | { |
| 6095 | return ValidateGenOrDelete(context, n); |
| 6096 | } |
| 6097 | |
| 6098 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 6099 | { |
| 6100 | return ValidateGenOrDelete(context, n); |
| 6101 | } |
| 6102 | |
| 6103 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 6104 | { |
| 6105 | return ValidateGenOrDelete(context, n); |
| 6106 | } |
| 6107 | |
| 6108 | bool ValidateDisable(Context *context, GLenum cap) |
| 6109 | { |
| 6110 | if (!ValidCap(context, cap, false)) |
| 6111 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6112 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6113 | return false; |
| 6114 | } |
| 6115 | |
| 6116 | return true; |
| 6117 | } |
| 6118 | |
| 6119 | bool ValidateEnable(Context *context, GLenum cap) |
| 6120 | { |
| 6121 | if (!ValidCap(context, cap, false)) |
| 6122 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6123 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6124 | return false; |
| 6125 | } |
| 6126 | |
| 6127 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 6128 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 6129 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6130 | context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6131 | |
| 6132 | // We also output an error message to the debugger window if tracing is active, so that |
| 6133 | // developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6134 | ERR() << kNoSampleAlphaToCoveragesLimitation; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6135 | return false; |
| 6136 | } |
| 6137 | |
| 6138 | return true; |
| 6139 | } |
| 6140 | |
| 6141 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 6142 | GLenum target, |
| 6143 | GLenum attachment, |
| 6144 | GLenum renderbuffertarget, |
| 6145 | GLuint renderbuffer) |
| 6146 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 6147 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6148 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6149 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6150 | return false; |
| 6151 | } |
| 6152 | |
| 6153 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0) |
| 6154 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6155 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6156 | return false; |
| 6157 | } |
| 6158 | |
| 6159 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 6160 | renderbuffertarget, renderbuffer); |
| 6161 | } |
| 6162 | |
| 6163 | bool ValidateFramebufferTexture2D(Context *context, |
| 6164 | GLenum target, |
| 6165 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6166 | TextureTarget textarget, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6167 | GLuint texture, |
| 6168 | GLint level) |
| 6169 | { |
| 6170 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 6171 | // extension |
| 6172 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 6173 | level != 0) |
| 6174 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6175 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6176 | return false; |
| 6177 | } |
| 6178 | |
| 6179 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6180 | { |
| 6181 | return false; |
| 6182 | } |
| 6183 | |
| 6184 | if (texture != 0) |
| 6185 | { |
| 6186 | gl::Texture *tex = context->getTexture(texture); |
| 6187 | ASSERT(tex); |
| 6188 | |
| 6189 | const gl::Caps &caps = context->getCaps(); |
| 6190 | |
| 6191 | switch (textarget) |
| 6192 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6193 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6194 | { |
| 6195 | if (level > gl::log2(caps.max2DTextureSize)) |
| 6196 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6197 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6198 | return false; |
| 6199 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6200 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6201 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6202 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6203 | return false; |
| 6204 | } |
| 6205 | } |
| 6206 | break; |
| 6207 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6208 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6209 | { |
| 6210 | if (level != 0) |
| 6211 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6212 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6213 | return false; |
| 6214 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6215 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6216 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6217 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6218 | return false; |
| 6219 | } |
| 6220 | } |
| 6221 | break; |
| 6222 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6223 | case TextureTarget::CubeMapNegativeX: |
| 6224 | case TextureTarget::CubeMapNegativeY: |
| 6225 | case TextureTarget::CubeMapNegativeZ: |
| 6226 | case TextureTarget::CubeMapPositiveX: |
| 6227 | case TextureTarget::CubeMapPositiveY: |
| 6228 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6229 | { |
| 6230 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6231 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6232 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6233 | return false; |
| 6234 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6235 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6236 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6237 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6238 | return false; |
| 6239 | } |
| 6240 | } |
| 6241 | break; |
| 6242 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6243 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6244 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6245 | if (context->getClientVersion() < ES_3_1 && |
| 6246 | !context->getExtensions().textureMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6247 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6248 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6249 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6250 | return false; |
| 6251 | } |
| 6252 | |
| 6253 | if (level != 0) |
| 6254 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6255 | context->validationError(GL_INVALID_VALUE, kLevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6256 | return false; |
| 6257 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6258 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6259 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6260 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6261 | return false; |
| 6262 | } |
| 6263 | } |
| 6264 | break; |
| 6265 | |
| 6266 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6267 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6268 | return false; |
| 6269 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | return true; |
| 6273 | } |
| 6274 | |
| 6275 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 6276 | { |
| 6277 | return ValidateGenOrDelete(context, n); |
| 6278 | } |
| 6279 | |
| 6280 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 6281 | { |
| 6282 | return ValidateGenOrDelete(context, n); |
| 6283 | } |
| 6284 | |
| 6285 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 6286 | { |
| 6287 | return ValidateGenOrDelete(context, n); |
| 6288 | } |
| 6289 | |
| 6290 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 6291 | { |
| 6292 | return ValidateGenOrDelete(context, n); |
| 6293 | } |
| 6294 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6295 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6296 | { |
| 6297 | if (!ValidTextureTarget(context, target)) |
| 6298 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6299 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6300 | return false; |
| 6301 | } |
| 6302 | |
Jamie Madill | cfc73cc | 2019-04-08 16:26:51 -0400 | [diff] [blame] | 6303 | Texture *texture = context->getTextureByType(target); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6304 | |
| 6305 | if (texture == nullptr) |
| 6306 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6307 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6308 | return false; |
| 6309 | } |
| 6310 | |
| 6311 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6312 | |
| 6313 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6314 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6315 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6316 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6317 | context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6318 | return false; |
| 6319 | } |
| 6320 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6321 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6322 | ? TextureTarget::CubeMapPositiveX |
| 6323 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6324 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6325 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6326 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6327 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6328 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6329 | return false; |
| 6330 | } |
| 6331 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6332 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6333 | bool formatUnsized = !format.sized; |
| 6334 | bool formatColorRenderableAndFilterable = |
| 6335 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6336 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6337 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6338 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6339 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6340 | return false; |
| 6341 | } |
| 6342 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6343 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6344 | // generation |
| 6345 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6346 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6347 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6348 | return false; |
| 6349 | } |
| 6350 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6351 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6352 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6353 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6354 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6355 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6356 | return false; |
| 6357 | } |
| 6358 | |
| 6359 | // Non-power of 2 ES2 check |
| 6360 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6361 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6362 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6363 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6364 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6365 | target == TextureType::CubeMap); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6366 | context->validationError(GL_INVALID_OPERATION, kTextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6367 | return false; |
| 6368 | } |
| 6369 | |
| 6370 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6371 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6372 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6373 | context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6374 | return false; |
| 6375 | } |
| 6376 | |
James Darpinian | 83b2f0e | 2018-11-27 15:56:01 -0800 | [diff] [blame] | 6377 | if (context->getExtensions().webglCompatibility && |
| 6378 | (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 || |
| 6379 | texture->getHeight(baseTarget, effectiveBaseLevel) == 0)) |
| 6380 | { |
| 6381 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize); |
| 6382 | return false; |
| 6383 | } |
| 6384 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6385 | return true; |
| 6386 | } |
| 6387 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6388 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6389 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6390 | GLenum pname, |
| 6391 | GLint *params) |
| 6392 | { |
| 6393 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6394 | } |
| 6395 | |
| 6396 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6397 | GLenum target, |
| 6398 | GLenum pname, |
| 6399 | GLint *params) |
| 6400 | { |
| 6401 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6402 | } |
| 6403 | |
| 6404 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 6405 | { |
| 6406 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6407 | } |
| 6408 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6409 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6410 | { |
| 6411 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6412 | } |
| 6413 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6414 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6415 | { |
| 6416 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6417 | } |
| 6418 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6419 | bool ValidateGetTexParameterIivOES(Context *context, |
| 6420 | TextureType target, |
| 6421 | GLenum pname, |
| 6422 | GLint *params) |
| 6423 | { |
| 6424 | if (context->getClientMajorVersion() < 3) |
| 6425 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6426 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6427 | return false; |
| 6428 | } |
| 6429 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6430 | } |
| 6431 | |
| 6432 | bool ValidateGetTexParameterIuivOES(Context *context, |
| 6433 | TextureType target, |
| 6434 | GLenum pname, |
| 6435 | GLuint *params) |
| 6436 | { |
| 6437 | if (context->getClientMajorVersion() < 3) |
| 6438 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6439 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6440 | return false; |
| 6441 | } |
| 6442 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6443 | } |
| 6444 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6445 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 6446 | { |
| 6447 | return ValidateGetUniformBase(context, program, location); |
| 6448 | } |
| 6449 | |
| 6450 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 6451 | { |
| 6452 | return ValidateGetUniformBase(context, program, location); |
| 6453 | } |
| 6454 | |
| 6455 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6456 | { |
| 6457 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6458 | } |
| 6459 | |
| 6460 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6461 | { |
| 6462 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6463 | } |
| 6464 | |
| 6465 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6466 | { |
| 6467 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6468 | } |
| 6469 | |
| 6470 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6471 | { |
| 6472 | if (!ValidCap(context, cap, true)) |
| 6473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6474 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6475 | return false; |
| 6476 | } |
| 6477 | |
| 6478 | return true; |
| 6479 | } |
| 6480 | |
| 6481 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 6482 | { |
| 6483 | if (context->hasActiveTransformFeedback(program)) |
| 6484 | { |
| 6485 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6486 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6487 | return false; |
| 6488 | } |
| 6489 | |
| 6490 | Program *programObject = GetValidProgram(context, program); |
| 6491 | if (!programObject) |
| 6492 | { |
| 6493 | return false; |
| 6494 | } |
| 6495 | |
| 6496 | return true; |
| 6497 | } |
| 6498 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6499 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6500 | GLint x, |
| 6501 | GLint y, |
| 6502 | GLsizei width, |
| 6503 | GLsizei height, |
| 6504 | GLenum format, |
| 6505 | GLenum type, |
| 6506 | void *pixels) |
| 6507 | { |
| 6508 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6509 | nullptr, pixels); |
| 6510 | } |
| 6511 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6512 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
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, false, ¶m); |
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 ValidateTexParameterfv(Context *context, |
| 6518 | TextureType target, |
| 6519 | GLenum pname, |
| 6520 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6521 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6522 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6523 | } |
| 6524 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6525 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6526 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6527 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6528 | } |
| 6529 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6530 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6531 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6532 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6533 | } |
| 6534 | |
| 6535 | bool ValidateTexParameterIivOES(Context *context, |
| 6536 | TextureType target, |
| 6537 | GLenum pname, |
| 6538 | const GLint *params) |
| 6539 | { |
| 6540 | if (context->getClientMajorVersion() < 3) |
| 6541 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6542 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6543 | return false; |
| 6544 | } |
| 6545 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6546 | } |
| 6547 | |
| 6548 | bool ValidateTexParameterIuivOES(Context *context, |
| 6549 | TextureType target, |
| 6550 | GLenum pname, |
| 6551 | const GLuint *params) |
| 6552 | { |
| 6553 | if (context->getClientMajorVersion() < 3) |
| 6554 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6555 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6556 | return false; |
| 6557 | } |
| 6558 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6559 | } |
| 6560 | |
| 6561 | bool ValidateUseProgram(Context *context, GLuint program) |
| 6562 | { |
| 6563 | if (program != 0) |
| 6564 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6565 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6566 | if (!programObject) |
| 6567 | { |
| 6568 | // ES 3.1.0 section 7.3 page 72 |
| 6569 | if (context->getShader(program)) |
| 6570 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6571 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6572 | return false; |
| 6573 | } |
| 6574 | else |
| 6575 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6576 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6577 | return false; |
| 6578 | } |
| 6579 | } |
| 6580 | if (!programObject->isLinked()) |
| 6581 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6582 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6583 | return false; |
| 6584 | } |
| 6585 | } |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 6586 | if (context->getState().isTransformFeedbackActiveUnpaused()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6587 | { |
| 6588 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6589 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6590 | return false; |
| 6591 | } |
| 6592 | |
| 6593 | return true; |
| 6594 | } |
| 6595 | |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6596 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences) |
| 6597 | { |
| 6598 | if (!context->getExtensions().fence) |
| 6599 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6600 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6601 | return false; |
| 6602 | } |
| 6603 | |
| 6604 | if (n < 0) |
| 6605 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6606 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6607 | return false; |
| 6608 | } |
| 6609 | |
| 6610 | return true; |
| 6611 | } |
| 6612 | |
| 6613 | bool ValidateFinishFenceNV(Context *context, GLuint fence) |
| 6614 | { |
| 6615 | if (!context->getExtensions().fence) |
| 6616 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6617 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6618 | return false; |
| 6619 | } |
| 6620 | |
| 6621 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6622 | |
| 6623 | if (fenceObject == nullptr) |
| 6624 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6625 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6626 | return false; |
| 6627 | } |
| 6628 | |
| 6629 | if (!fenceObject->isSet()) |
| 6630 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6631 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6632 | return false; |
| 6633 | } |
| 6634 | |
| 6635 | return true; |
| 6636 | } |
| 6637 | |
| 6638 | bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences) |
| 6639 | { |
| 6640 | if (!context->getExtensions().fence) |
| 6641 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6642 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6643 | return false; |
| 6644 | } |
| 6645 | |
| 6646 | if (n < 0) |
| 6647 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6648 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6649 | return false; |
| 6650 | } |
| 6651 | |
| 6652 | return true; |
| 6653 | } |
| 6654 | |
| 6655 | bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params) |
| 6656 | { |
| 6657 | if (!context->getExtensions().fence) |
| 6658 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6659 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6660 | return false; |
| 6661 | } |
| 6662 | |
| 6663 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6664 | |
| 6665 | if (fenceObject == nullptr) |
| 6666 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6667 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6668 | return false; |
| 6669 | } |
| 6670 | |
| 6671 | if (!fenceObject->isSet()) |
| 6672 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6673 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6674 | return false; |
| 6675 | } |
| 6676 | |
| 6677 | switch (pname) |
| 6678 | { |
| 6679 | case GL_FENCE_STATUS_NV: |
| 6680 | case GL_FENCE_CONDITION_NV: |
| 6681 | break; |
| 6682 | |
| 6683 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6684 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6685 | return false; |
| 6686 | } |
| 6687 | |
| 6688 | return true; |
| 6689 | } |
| 6690 | |
| 6691 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6692 | { |
| 6693 | if (!context->getExtensions().robustness) |
| 6694 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6695 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6696 | return false; |
| 6697 | } |
| 6698 | |
| 6699 | return true; |
| 6700 | } |
| 6701 | |
| 6702 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
| 6703 | GLuint shader, |
| 6704 | GLsizei bufsize, |
| 6705 | GLsizei *length, |
| 6706 | GLchar *source) |
| 6707 | { |
| 6708 | if (!context->getExtensions().translatedShaderSource) |
| 6709 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6710 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6711 | return false; |
| 6712 | } |
| 6713 | |
| 6714 | if (bufsize < 0) |
| 6715 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6716 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6717 | return false; |
| 6718 | } |
| 6719 | |
| 6720 | Shader *shaderObject = context->getShader(shader); |
| 6721 | |
| 6722 | if (!shaderObject) |
| 6723 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6724 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6725 | return false; |
| 6726 | } |
| 6727 | |
| 6728 | return true; |
| 6729 | } |
| 6730 | |
| 6731 | bool ValidateIsFenceNV(Context *context, GLuint fence) |
| 6732 | { |
| 6733 | if (!context->getExtensions().fence) |
| 6734 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6735 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6736 | return false; |
| 6737 | } |
| 6738 | |
| 6739 | return true; |
| 6740 | } |
| 6741 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6742 | bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition) |
| 6743 | { |
| 6744 | if (!context->getExtensions().fence) |
| 6745 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6746 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6747 | return false; |
| 6748 | } |
| 6749 | |
| 6750 | if (condition != GL_ALL_COMPLETED_NV) |
| 6751 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6752 | context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6753 | return false; |
| 6754 | } |
| 6755 | |
| 6756 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6757 | |
| 6758 | if (fenceObject == nullptr) |
| 6759 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6760 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6761 | return false; |
| 6762 | } |
| 6763 | |
| 6764 | return true; |
| 6765 | } |
| 6766 | |
| 6767 | bool ValidateTestFenceNV(Context *context, GLuint fence) |
| 6768 | { |
| 6769 | if (!context->getExtensions().fence) |
| 6770 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6771 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6772 | return false; |
| 6773 | } |
| 6774 | |
| 6775 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6776 | |
| 6777 | if (fenceObject == nullptr) |
| 6778 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6779 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6780 | return false; |
| 6781 | } |
| 6782 | |
| 6783 | if (fenceObject->isSet() != GL_TRUE) |
| 6784 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6785 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6786 | return false; |
| 6787 | } |
| 6788 | |
| 6789 | return true; |
| 6790 | } |
| 6791 | |
| 6792 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6793 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6794 | GLsizei levels, |
| 6795 | GLenum internalformat, |
| 6796 | GLsizei width, |
| 6797 | GLsizei height) |
| 6798 | { |
| 6799 | if (!context->getExtensions().textureStorage) |
| 6800 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6801 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6802 | return false; |
| 6803 | } |
| 6804 | |
| 6805 | if (context->getClientMajorVersion() < 3) |
| 6806 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6807 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6808 | height); |
| 6809 | } |
| 6810 | |
| 6811 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6812 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6813 | 1); |
| 6814 | } |
| 6815 | |
| 6816 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 6817 | { |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 6818 | if (!context->getExtensions().instancedArraysANGLE) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6819 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6820 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6821 | return false; |
| 6822 | } |
| 6823 | |
| 6824 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6825 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6826 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6827 | return false; |
| 6828 | } |
| 6829 | |
| 6830 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 6831 | { |
| 6832 | if (index == 0 && divisor != 0) |
| 6833 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6834 | context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6835 | |
| 6836 | // We also output an error message to the debugger window if tracing is active, so |
| 6837 | // that developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6838 | ERR() << kAttributeZeroRequiresDivisorLimitation; |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6839 | return false; |
| 6840 | } |
| 6841 | } |
| 6842 | |
| 6843 | return true; |
| 6844 | } |
| 6845 | |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 6846 | bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor) |
| 6847 | { |
| 6848 | if (!context->getExtensions().instancedArraysEXT) |
| 6849 | { |
| 6850 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6851 | return false; |
| 6852 | } |
| 6853 | |
| 6854 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6855 | { |
| 6856 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
| 6857 | return false; |
| 6858 | } |
| 6859 | |
| 6860 | return true; |
| 6861 | } |
| 6862 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6863 | bool ValidateTexImage3DOES(Context *context, |
| 6864 | GLenum target, |
| 6865 | GLint level, |
| 6866 | GLenum internalformat, |
| 6867 | GLsizei width, |
| 6868 | GLsizei height, |
| 6869 | GLsizei depth, |
| 6870 | GLint border, |
| 6871 | GLenum format, |
| 6872 | GLenum type, |
| 6873 | const void *pixels) |
| 6874 | { |
| 6875 | UNIMPLEMENTED(); // FIXME |
| 6876 | return false; |
| 6877 | } |
| 6878 | |
| 6879 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 6880 | { |
| 6881 | if (!context->getExtensions().debugMarker) |
| 6882 | { |
| 6883 | // The debug marker calls should not set error state |
| 6884 | // 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] | 6885 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6886 | return false; |
| 6887 | } |
| 6888 | |
| 6889 | return true; |
| 6890 | } |
| 6891 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6892 | bool ValidateTexStorage1DEXT(Context *context, |
| 6893 | GLenum target, |
| 6894 | GLsizei levels, |
| 6895 | GLenum internalformat, |
| 6896 | GLsizei width) |
| 6897 | { |
| 6898 | UNIMPLEMENTED(); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6899 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6900 | return false; |
| 6901 | } |
| 6902 | |
| 6903 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6904 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6905 | GLsizei levels, |
| 6906 | GLenum internalformat, |
| 6907 | GLsizei width, |
| 6908 | GLsizei height, |
| 6909 | GLsizei depth) |
| 6910 | { |
| 6911 | if (!context->getExtensions().textureStorage) |
| 6912 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6913 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6914 | return false; |
| 6915 | } |
| 6916 | |
| 6917 | if (context->getClientMajorVersion() < 3) |
| 6918 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6919 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6920 | return false; |
| 6921 | } |
| 6922 | |
| 6923 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 6924 | depth); |
| 6925 | } |
| 6926 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6927 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 6928 | { |
| 6929 | if (!context->getExtensions().parallelShaderCompile) |
| 6930 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6931 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6932 | return false; |
| 6933 | } |
| 6934 | return true; |
| 6935 | } |
| 6936 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6937 | bool ValidateMultiDrawArraysANGLE(Context *context, |
| 6938 | PrimitiveMode mode, |
| 6939 | const GLint *firsts, |
| 6940 | const GLsizei *counts, |
| 6941 | GLsizei drawcount) |
| 6942 | { |
| 6943 | if (!context->getExtensions().multiDraw) |
| 6944 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6945 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6946 | return false; |
| 6947 | } |
| 6948 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6949 | { |
| 6950 | if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID])) |
| 6951 | { |
| 6952 | return false; |
| 6953 | } |
| 6954 | } |
| 6955 | return true; |
| 6956 | } |
| 6957 | |
| 6958 | bool ValidateMultiDrawElementsANGLE(Context *context, |
| 6959 | PrimitiveMode mode, |
| 6960 | const GLsizei *counts, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 6961 | DrawElementsType type, |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 6962 | const GLvoid *const *indices, |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6963 | GLsizei drawcount) |
| 6964 | { |
| 6965 | if (!context->getExtensions().multiDraw) |
| 6966 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6967 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6968 | return false; |
| 6969 | } |
| 6970 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6971 | { |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 6972 | if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID])) |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6973 | { |
| 6974 | return false; |
| 6975 | } |
| 6976 | } |
| 6977 | return true; |
| 6978 | } |
| 6979 | |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 6980 | bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked) |
| 6981 | { |
| 6982 | if (!context->getExtensions().provokingVertex) |
| 6983 | { |
| 6984 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6985 | return false; |
| 6986 | } |
| 6987 | |
| 6988 | switch (modePacked) |
| 6989 | { |
| 6990 | case ProvokingVertex::FirstVertexConvention: |
| 6991 | case ProvokingVertex::LastVertexConvention: |
| 6992 | break; |
| 6993 | default: |
| 6994 | context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex); |
| 6995 | return false; |
| 6996 | } |
| 6997 | |
| 6998 | return true; |
| 6999 | } |
| 7000 | |
Jamie Madill | a541048 | 2019-01-31 19:55:55 -0500 | [diff] [blame] | 7001 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 7002 | { |
| 7003 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 7004 | |
| 7005 | switch (target) |
| 7006 | { |
| 7007 | case TextureType::Rectangle: |
| 7008 | ASSERT(!context->getExtensions().textureRectangle); |
| 7009 | context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported); |
| 7010 | break; |
| 7011 | |
| 7012 | case TextureType::_3D: |
| 7013 | case TextureType::_2DArray: |
| 7014 | ASSERT(context->getClientMajorVersion() < 3); |
| 7015 | context->validationError(GL_INVALID_ENUM, kES3Required); |
| 7016 | break; |
| 7017 | |
| 7018 | case TextureType::_2DMultisample: |
| 7019 | ASSERT(context->getClientVersion() < Version(3, 1) && |
| 7020 | !context->getExtensions().textureMultisample); |
| 7021 | context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required); |
| 7022 | break; |
| 7023 | |
| 7024 | case TextureType::_2DMultisampleArray: |
| 7025 | ASSERT(!context->getExtensions().textureStorageMultisample2DArray); |
| 7026 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
| 7027 | break; |
| 7028 | |
| 7029 | case TextureType::External: |
| 7030 | ASSERT(!context->getExtensions().eglImageExternal && |
| 7031 | !context->getExtensions().eglStreamConsumerExternal); |
| 7032 | context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported); |
| 7033 | break; |
| 7034 | |
| 7035 | default: |
| 7036 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
| 7037 | } |
| 7038 | } |
| 7039 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 7040 | } // namespace gl |