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