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