Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES2.cpp: Validation functions for OpenGL ES 2.0 entry point parameters |
| 8 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES2_autogen.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 10 | |
| 11 | #include <cstdint> |
| 12 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 13 | #include "common/mathutil.h" |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 14 | #include "common/string_utils.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 15 | #include "common/utilities.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 16 | #include "libANGLE/Context.h" |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 17 | #include "libANGLE/ErrorStrings.h" |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 18 | #include "libANGLE/Fence.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 19 | #include "libANGLE/Framebuffer.h" |
| 20 | #include "libANGLE/FramebufferAttachment.h" |
| 21 | #include "libANGLE/Renderbuffer.h" |
| 22 | #include "libANGLE/Shader.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/Texture.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 24 | #include "libANGLE/Uniform.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 25 | #include "libANGLE/VertexArray.h" |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 26 | #include "libANGLE/formatutils.h" |
| 27 | #include "libANGLE/validationES.h" |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 28 | #include "libANGLE/validationES2.h" |
| 29 | #include "libANGLE/validationES3_autogen.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 30 | |
| 31 | namespace gl |
| 32 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 33 | using namespace err; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 34 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 35 | namespace |
| 36 | { |
| 37 | |
| 38 | bool IsPartialBlit(gl::Context *context, |
| 39 | const FramebufferAttachment *readBuffer, |
| 40 | const FramebufferAttachment *writeBuffer, |
| 41 | GLint srcX0, |
| 42 | GLint srcY0, |
| 43 | GLint srcX1, |
| 44 | GLint srcY1, |
| 45 | GLint dstX0, |
| 46 | GLint dstY0, |
| 47 | GLint dstX1, |
| 48 | GLint dstY1) |
| 49 | { |
| 50 | const Extents &writeSize = writeBuffer->getSize(); |
| 51 | const Extents &readSize = readBuffer->getSize(); |
| 52 | |
| 53 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width || |
| 54 | dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height) |
| 55 | { |
| 56 | return true; |
| 57 | } |
| 58 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 59 | if (context->getState().isScissorTestEnabled()) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 60 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 61 | const Rectangle &scissor = context->getState().getScissor(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 62 | return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width || |
| 63 | scissor.height < writeSize.height; |
| 64 | } |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 69 | template <typename T> |
| 70 | bool ValidatePathInstances(gl::Context *context, |
| 71 | GLsizei numPaths, |
| 72 | const void *paths, |
| 73 | GLuint pathBase) |
| 74 | { |
| 75 | const auto *array = static_cast<const T *>(paths); |
| 76 | |
| 77 | for (GLsizei i = 0; i < numPaths; ++i) |
| 78 | { |
| 79 | const GLuint pathName = array[i] + pathBase; |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 80 | if (context->isPathGenerated(pathName) && !context->isPath(pathName)) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 81 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 82 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 83 | return false; |
| 84 | } |
| 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool ValidateInstancedPathParameters(gl::Context *context, |
| 90 | GLsizei numPaths, |
| 91 | GLenum pathNameType, |
| 92 | const void *paths, |
| 93 | GLuint pathBase, |
| 94 | GLenum transformType, |
| 95 | const GLfloat *transformValues) |
| 96 | { |
| 97 | if (!context->getExtensions().pathRendering) |
| 98 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 99 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | if (paths == nullptr) |
| 104 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 105 | context->validationError(GL_INVALID_VALUE, kInvalidPathNameArray); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 106 | return false; |
| 107 | } |
| 108 | |
| 109 | if (numPaths < 0) |
| 110 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 111 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumPaths); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 112 | return false; |
| 113 | } |
| 114 | |
| 115 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths)) |
| 116 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 117 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 118 | return false; |
| 119 | } |
| 120 | |
| 121 | std::uint32_t pathNameTypeSize = 0; |
| 122 | std::uint32_t componentCount = 0; |
| 123 | |
| 124 | switch (pathNameType) |
| 125 | { |
| 126 | case GL_UNSIGNED_BYTE: |
| 127 | pathNameTypeSize = sizeof(GLubyte); |
| 128 | if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase)) |
| 129 | return false; |
| 130 | break; |
| 131 | |
| 132 | case GL_BYTE: |
| 133 | pathNameTypeSize = sizeof(GLbyte); |
| 134 | if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase)) |
| 135 | return false; |
| 136 | break; |
| 137 | |
| 138 | case GL_UNSIGNED_SHORT: |
| 139 | pathNameTypeSize = sizeof(GLushort); |
| 140 | if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase)) |
| 141 | return false; |
| 142 | break; |
| 143 | |
| 144 | case GL_SHORT: |
| 145 | pathNameTypeSize = sizeof(GLshort); |
| 146 | if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase)) |
| 147 | return false; |
| 148 | break; |
| 149 | |
| 150 | case GL_UNSIGNED_INT: |
| 151 | pathNameTypeSize = sizeof(GLuint); |
| 152 | if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase)) |
| 153 | return false; |
| 154 | break; |
| 155 | |
| 156 | case GL_INT: |
| 157 | pathNameTypeSize = sizeof(GLint); |
| 158 | if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase)) |
| 159 | return false; |
| 160 | break; |
| 161 | |
| 162 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 163 | context->validationError(GL_INVALID_ENUM, kInvalidPathNameType); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 164 | return false; |
| 165 | } |
| 166 | |
| 167 | switch (transformType) |
| 168 | { |
| 169 | case GL_NONE: |
| 170 | componentCount = 0; |
| 171 | break; |
| 172 | case GL_TRANSLATE_X_CHROMIUM: |
| 173 | case GL_TRANSLATE_Y_CHROMIUM: |
| 174 | componentCount = 1; |
| 175 | break; |
| 176 | case GL_TRANSLATE_2D_CHROMIUM: |
| 177 | componentCount = 2; |
| 178 | break; |
| 179 | case GL_TRANSLATE_3D_CHROMIUM: |
| 180 | componentCount = 3; |
| 181 | break; |
| 182 | case GL_AFFINE_2D_CHROMIUM: |
| 183 | case GL_TRANSPOSE_AFFINE_2D_CHROMIUM: |
| 184 | componentCount = 6; |
| 185 | break; |
| 186 | case GL_AFFINE_3D_CHROMIUM: |
| 187 | case GL_TRANSPOSE_AFFINE_3D_CHROMIUM: |
| 188 | componentCount = 12; |
| 189 | break; |
| 190 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 191 | context->validationError(GL_INVALID_ENUM, kInvalidTransformation); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 192 | return false; |
| 193 | } |
| 194 | if (componentCount != 0 && transformValues == nullptr) |
| 195 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 196 | context->validationError(GL_INVALID_VALUE, kNoTransformArray); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 197 | return false; |
| 198 | } |
| 199 | |
| 200 | angle::CheckedNumeric<std::uint32_t> checkedSize(0); |
| 201 | checkedSize += (numPaths * pathNameTypeSize); |
| 202 | checkedSize += (numPaths * sizeof(GLfloat) * componentCount); |
| 203 | if (!checkedSize.IsValid()) |
| 204 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 205 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 206 | return false; |
| 207 | } |
| 208 | |
| 209 | return true; |
| 210 | } |
| 211 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 212 | bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 213 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 214 | // Table 1.1 from the CHROMIUM_copy_texture spec |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 215 | switch (GetUnsizedFormat(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 216 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 217 | case GL_RED: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 218 | case GL_ALPHA: |
| 219 | case GL_LUMINANCE: |
| 220 | case GL_LUMINANCE_ALPHA: |
| 221 | case GL_RGB: |
| 222 | case GL_RGBA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 223 | case GL_RGB8: |
| 224 | case GL_RGBA8: |
| 225 | case GL_BGRA_EXT: |
| 226 | case GL_BGRA8_EXT: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 227 | return true; |
| 228 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 229 | default: |
| 230 | return false; |
| 231 | } |
| 232 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 233 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 234 | bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat) |
| 235 | { |
| 236 | return IsValidCopyTextureSourceInternalFormatEnum(internalFormat); |
| 237 | } |
| 238 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 239 | bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat) |
| 240 | { |
| 241 | // Table 1.0 from the CHROMIUM_copy_texture spec |
| 242 | switch (internalFormat) |
| 243 | { |
| 244 | case GL_RGB: |
| 245 | case GL_RGBA: |
| 246 | case GL_RGB8: |
| 247 | case GL_RGBA8: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 248 | case GL_BGRA_EXT: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 249 | case GL_BGRA8_EXT: |
| 250 | case GL_SRGB_EXT: |
| 251 | case GL_SRGB_ALPHA_EXT: |
| 252 | case GL_R8: |
| 253 | case GL_R8UI: |
| 254 | case GL_RG8: |
| 255 | case GL_RG8UI: |
| 256 | case GL_SRGB8: |
| 257 | case GL_RGB565: |
| 258 | case GL_RGB8UI: |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 259 | case GL_RGB10_A2: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 260 | case GL_SRGB8_ALPHA8: |
| 261 | case GL_RGB5_A1: |
| 262 | case GL_RGBA4: |
| 263 | case GL_RGBA8UI: |
| 264 | case GL_RGB9_E5: |
| 265 | case GL_R16F: |
| 266 | case GL_R32F: |
| 267 | case GL_RG16F: |
| 268 | case GL_RG32F: |
| 269 | case GL_RGB16F: |
| 270 | case GL_RGB32F: |
| 271 | case GL_RGBA16F: |
| 272 | case GL_RGBA32F: |
| 273 | case GL_R11F_G11F_B10F: |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 274 | case GL_LUMINANCE: |
| 275 | case GL_LUMINANCE_ALPHA: |
| 276 | case GL_ALPHA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 277 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 278 | |
| 279 | default: |
| 280 | return false; |
| 281 | } |
| 282 | } |
| 283 | |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 284 | bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat) |
| 285 | { |
| 286 | return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat); |
| 287 | } |
| 288 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 289 | bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type) |
| 290 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 291 | if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 292 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 293 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 294 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 297 | if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat)) |
| 298 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 299 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 303 | const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type); |
| 304 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 305 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 306 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 307 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return true; |
| 311 | } |
| 312 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 313 | bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 314 | { |
| 315 | switch (target) |
| 316 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 317 | case TextureTarget::_2D: |
| 318 | case TextureTarget::CubeMapNegativeX: |
| 319 | case TextureTarget::CubeMapNegativeY: |
| 320 | case TextureTarget::CubeMapNegativeZ: |
| 321 | case TextureTarget::CubeMapPositiveX: |
| 322 | case TextureTarget::CubeMapPositiveY: |
| 323 | case TextureTarget::CubeMapPositiveZ: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 324 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 325 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 326 | case TextureTarget::Rectangle: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 327 | return context->getExtensions().textureRectangle; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 328 | |
| 329 | default: |
| 330 | return false; |
| 331 | } |
| 332 | } |
| 333 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 334 | bool IsValidCopyTextureDestinationTarget(Context *context, |
| 335 | TextureType textureType, |
| 336 | TextureTarget target) |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 337 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 338 | return TextureTargetToType(target) == textureType; |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 341 | bool IsValidCopyTextureSourceTarget(Context *context, TextureType type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 342 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 343 | switch (type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 344 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 345 | case TextureType::_2D: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 346 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 347 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 348 | return context->getExtensions().textureRectangle; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 349 | case TextureType::External: |
| 350 | return context->getExtensions().eglImageExternal; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 351 | default: |
| 352 | return false; |
| 353 | } |
| 354 | } |
| 355 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 356 | bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 357 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 358 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 359 | { |
| 360 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 363 | if (level > 0 && context->getClientVersion() < ES_3_0) |
| 364 | { |
| 365 | return false; |
| 366 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 367 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 368 | return true; |
| 369 | } |
| 370 | |
| 371 | bool IsValidCopyTextureDestinationLevel(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 372 | TextureType type, |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 373 | GLint level, |
| 374 | GLsizei width, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 375 | GLsizei height, |
| 376 | bool isSubImage) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 377 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 378 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 379 | { |
| 380 | return false; |
| 381 | } |
| 382 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 383 | if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage)) |
| 384 | { |
| 385 | return false; |
| 386 | } |
| 387 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 388 | const Caps &caps = context->getCaps(); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 389 | switch (type) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 390 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 391 | case TextureType::_2D: |
| 392 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 393 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
| 394 | case TextureType::Rectangle: |
| 395 | ASSERT(level == 0); |
| 396 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 397 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 398 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 399 | case TextureType::CubeMap: |
| 400 | return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) && |
| 401 | static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level); |
| 402 | default: |
| 403 | return true; |
| 404 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 407 | bool IsValidStencilFunc(GLenum func) |
| 408 | { |
| 409 | switch (func) |
| 410 | { |
| 411 | case GL_NEVER: |
| 412 | case GL_ALWAYS: |
| 413 | case GL_LESS: |
| 414 | case GL_LEQUAL: |
| 415 | case GL_EQUAL: |
| 416 | case GL_GEQUAL: |
| 417 | case GL_GREATER: |
| 418 | case GL_NOTEQUAL: |
| 419 | return true; |
| 420 | |
| 421 | default: |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | bool IsValidStencilFace(GLenum face) |
| 427 | { |
| 428 | switch (face) |
| 429 | { |
| 430 | case GL_FRONT: |
| 431 | case GL_BACK: |
| 432 | case GL_FRONT_AND_BACK: |
| 433 | return true; |
| 434 | |
| 435 | default: |
| 436 | return false; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | bool IsValidStencilOp(GLenum op) |
| 441 | { |
| 442 | switch (op) |
| 443 | { |
| 444 | case GL_ZERO: |
| 445 | case GL_KEEP: |
| 446 | case GL_REPLACE: |
| 447 | case GL_INCR: |
| 448 | case GL_DECR: |
| 449 | case GL_INVERT: |
| 450 | case GL_INCR_WRAP: |
| 451 | case GL_DECR_WRAP: |
| 452 | return true; |
| 453 | |
| 454 | default: |
| 455 | return false; |
| 456 | } |
| 457 | } |
| 458 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 459 | bool ValidateES2CopyTexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 460 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 461 | GLint level, |
| 462 | GLenum internalformat, |
| 463 | bool isSubImage, |
| 464 | GLint xoffset, |
| 465 | GLint yoffset, |
| 466 | GLint x, |
| 467 | GLint y, |
| 468 | GLsizei width, |
| 469 | GLsizei height, |
| 470 | GLint border) |
| 471 | { |
| 472 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 474 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 475 | return false; |
| 476 | } |
| 477 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 478 | TextureType texType = TextureTargetToType(target); |
| 479 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 480 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 481 | // Error is already handled. |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 482 | return false; |
| 483 | } |
| 484 | |
| 485 | Format textureFormat = Format::Invalid(); |
| 486 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 487 | xoffset, yoffset, 0, x, y, width, height, border, |
| 488 | &textureFormat)) |
| 489 | { |
| 490 | return false; |
| 491 | } |
| 492 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 493 | const gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 494 | GLenum colorbufferFormat = |
| 495 | framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat; |
| 496 | const auto &formatInfo = *textureFormat.info; |
| 497 | |
| 498 | // [OpenGL ES 2.0.24] table 3.9 |
| 499 | if (isSubImage) |
| 500 | { |
| 501 | switch (formatInfo.format) |
| 502 | { |
| 503 | case GL_ALPHA: |
| 504 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 505 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 506 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 507 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 508 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 509 | return false; |
| 510 | } |
| 511 | break; |
| 512 | case GL_LUMINANCE: |
| 513 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 514 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 515 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 516 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT && |
| 517 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 518 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 519 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 520 | return false; |
| 521 | } |
| 522 | break; |
| 523 | case GL_RED_EXT: |
| 524 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 525 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 526 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 527 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F && |
| 528 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 529 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 530 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 531 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 532 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 533 | return false; |
| 534 | } |
| 535 | break; |
| 536 | case GL_RG_EXT: |
| 537 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 538 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 539 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 540 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 541 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 542 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 543 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 544 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | break; |
| 548 | case GL_RGB: |
| 549 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 550 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 551 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 552 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 553 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 554 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 555 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 556 | return false; |
| 557 | } |
| 558 | break; |
| 559 | case GL_LUMINANCE_ALPHA: |
| 560 | case GL_RGBA: |
| 561 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 562 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F && |
| 563 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 564 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 565 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 566 | return false; |
| 567 | } |
| 568 | break; |
| 569 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 570 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 571 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 572 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 573 | case GL_ETC1_RGB8_OES: |
| 574 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 575 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 576 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 577 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 578 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 579 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 580 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 581 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 582 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 583 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 584 | return false; |
| 585 | case GL_DEPTH_COMPONENT: |
| 586 | case GL_DEPTH_STENCIL_OES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 587 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 588 | return false; |
| 589 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 590 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | |
| 594 | if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat) |
| 595 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 596 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 597 | return false; |
| 598 | } |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | switch (internalformat) |
| 603 | { |
| 604 | case GL_ALPHA: |
| 605 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
| 606 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 607 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 608 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 609 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 610 | return false; |
| 611 | } |
| 612 | break; |
| 613 | case GL_LUMINANCE: |
| 614 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 615 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 616 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 617 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 618 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 619 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 620 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 621 | return false; |
| 622 | } |
| 623 | break; |
| 624 | case GL_RED_EXT: |
| 625 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 626 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 627 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 628 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 629 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 630 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 631 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 632 | return false; |
| 633 | } |
| 634 | break; |
| 635 | case GL_RG_EXT: |
| 636 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 637 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 638 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 639 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 640 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 641 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 642 | return false; |
| 643 | } |
| 644 | break; |
| 645 | case GL_RGB: |
| 646 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 647 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 648 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 649 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 650 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 651 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 652 | return false; |
| 653 | } |
| 654 | break; |
| 655 | case GL_LUMINANCE_ALPHA: |
| 656 | case GL_RGBA: |
| 657 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 658 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 659 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 660 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 661 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 662 | return false; |
| 663 | } |
| 664 | break; |
| 665 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 666 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 667 | if (context->getExtensions().textureCompressionDXT1) |
| 668 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 669 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 670 | return false; |
| 671 | } |
| 672 | else |
| 673 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 674 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 675 | return false; |
| 676 | } |
| 677 | break; |
| 678 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 679 | if (context->getExtensions().textureCompressionDXT3) |
| 680 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 681 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 682 | return false; |
| 683 | } |
| 684 | else |
| 685 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 686 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 687 | return false; |
| 688 | } |
| 689 | break; |
| 690 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 691 | if (context->getExtensions().textureCompressionDXT5) |
| 692 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 693 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | else |
| 697 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 698 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 699 | return false; |
| 700 | } |
| 701 | break; |
| 702 | case GL_ETC1_RGB8_OES: |
| 703 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 704 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 705 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 706 | return false; |
| 707 | } |
| 708 | else |
| 709 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 710 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 711 | return false; |
| 712 | } |
| 713 | break; |
| 714 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 715 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 716 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 717 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 718 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 719 | if (context->getExtensions().lossyETCDecode) |
| 720 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 721 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 722 | return false; |
| 723 | } |
| 724 | else |
| 725 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 726 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 727 | return false; |
| 728 | } |
| 729 | break; |
| 730 | case GL_DEPTH_COMPONENT: |
| 731 | case GL_DEPTH_COMPONENT16: |
| 732 | case GL_DEPTH_COMPONENT32_OES: |
| 733 | case GL_DEPTH_STENCIL_OES: |
| 734 | case GL_DEPTH24_STENCIL8_OES: |
| 735 | if (context->getExtensions().depthTextures) |
| 736 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 737 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 738 | return false; |
| 739 | } |
| 740 | else |
| 741 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 742 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 743 | return false; |
| 744 | } |
| 745 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 746 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 747 | return false; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 752 | return (width > 0 && height > 0); |
| 753 | } |
| 754 | |
| 755 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 756 | { |
| 757 | switch (cap) |
| 758 | { |
| 759 | // EXT_multisample_compatibility |
| 760 | case GL_MULTISAMPLE_EXT: |
| 761 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 762 | return context->getExtensions().multisampleCompatibility; |
| 763 | |
| 764 | case GL_CULL_FACE: |
| 765 | case GL_POLYGON_OFFSET_FILL: |
| 766 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 767 | case GL_SAMPLE_COVERAGE: |
| 768 | case GL_SCISSOR_TEST: |
| 769 | case GL_STENCIL_TEST: |
| 770 | case GL_DEPTH_TEST: |
| 771 | case GL_BLEND: |
| 772 | case GL_DITHER: |
| 773 | return true; |
| 774 | |
| 775 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 776 | case GL_RASTERIZER_DISCARD: |
| 777 | return (context->getClientMajorVersion() >= 3); |
| 778 | |
| 779 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 780 | case GL_DEBUG_OUTPUT: |
| 781 | return context->getExtensions().debug; |
| 782 | |
| 783 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 784 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 785 | |
| 786 | case GL_CLIENT_ARRAYS_ANGLE: |
| 787 | return queryOnly && context->getExtensions().clientArrays; |
| 788 | |
| 789 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 790 | return context->getExtensions().sRGBWriteControl; |
| 791 | |
| 792 | case GL_SAMPLE_MASK: |
| 793 | return context->getClientVersion() >= Version(3, 1); |
| 794 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 795 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 796 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 797 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 798 | // GLES1 emulation: GLES1-specific caps |
| 799 | case GL_ALPHA_TEST: |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 800 | case GL_VERTEX_ARRAY: |
| 801 | case GL_NORMAL_ARRAY: |
| 802 | case GL_COLOR_ARRAY: |
| 803 | case GL_TEXTURE_COORD_ARRAY: |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 804 | case GL_TEXTURE_2D: |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 805 | case GL_LIGHTING: |
| 806 | case GL_LIGHT0: |
| 807 | case GL_LIGHT1: |
| 808 | case GL_LIGHT2: |
| 809 | case GL_LIGHT3: |
| 810 | case GL_LIGHT4: |
| 811 | case GL_LIGHT5: |
| 812 | case GL_LIGHT6: |
| 813 | case GL_LIGHT7: |
| 814 | case GL_NORMALIZE: |
| 815 | case GL_RESCALE_NORMAL: |
| 816 | case GL_COLOR_MATERIAL: |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 817 | case GL_CLIP_PLANE0: |
| 818 | case GL_CLIP_PLANE1: |
| 819 | case GL_CLIP_PLANE2: |
| 820 | case GL_CLIP_PLANE3: |
| 821 | case GL_CLIP_PLANE4: |
| 822 | case GL_CLIP_PLANE5: |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 823 | case GL_FOG: |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 824 | case GL_POINT_SMOOTH: |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 825 | case GL_LINE_SMOOTH: |
| 826 | case GL_COLOR_LOGIC_OP: |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 827 | return context->getClientVersion() < Version(2, 0); |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 828 | case GL_POINT_SIZE_ARRAY_OES: |
| 829 | return context->getClientVersion() < Version(2, 0) && |
| 830 | context->getExtensions().pointSizeArray; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 831 | case GL_TEXTURE_CUBE_MAP: |
| 832 | return context->getClientVersion() < Version(2, 0) && |
| 833 | context->getExtensions().textureCubeMap; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 834 | case GL_POINT_SPRITE_OES: |
| 835 | return context->getClientVersion() < Version(2, 0) && |
| 836 | context->getExtensions().pointSprite; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 837 | default: |
| 838 | return false; |
| 839 | } |
| 840 | } |
| 841 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 842 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 843 | // 3.1. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 844 | bool IsValidESSLCharacter(unsigned char c) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 845 | { |
| 846 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 847 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && |
| 848 | c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 849 | { |
| 850 | return true; |
| 851 | } |
| 852 | |
| 853 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 854 | if (c >= 9 && c <= 13) |
| 855 | { |
| 856 | return true; |
| 857 | } |
| 858 | |
| 859 | return false; |
| 860 | } |
| 861 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 862 | bool IsValidESSLString(const char *str, size_t len) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 863 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 864 | for (size_t i = 0; i < len; i++) |
| 865 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 866 | if (!IsValidESSLCharacter(str[i])) |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 867 | { |
| 868 | return false; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 873 | } |
| 874 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 875 | bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed) |
| 876 | { |
| 877 | enum class ParseState |
| 878 | { |
| 879 | // Have not seen an ASCII non-whitespace character yet on |
| 880 | // this line. Possible that we might see a preprocessor |
| 881 | // directive. |
| 882 | BEGINING_OF_LINE, |
| 883 | |
| 884 | // Have seen at least one ASCII non-whitespace character |
| 885 | // on this line. |
| 886 | MIDDLE_OF_LINE, |
| 887 | |
| 888 | // Handling a preprocessor directive. Passes through all |
| 889 | // characters up to the end of the line. Disables comment |
| 890 | // processing. |
| 891 | IN_PREPROCESSOR_DIRECTIVE, |
| 892 | |
| 893 | // Handling a single-line comment. The comment text is |
| 894 | // replaced with a single space. |
| 895 | IN_SINGLE_LINE_COMMENT, |
| 896 | |
| 897 | // Handling a multi-line comment. Newlines are passed |
| 898 | // through to preserve line numbers. |
| 899 | IN_MULTI_LINE_COMMENT |
| 900 | }; |
| 901 | |
| 902 | ParseState state = ParseState::BEGINING_OF_LINE; |
| 903 | size_t pos = 0; |
| 904 | |
| 905 | while (pos < len) |
| 906 | { |
| 907 | char c = str[pos]; |
| 908 | char next = pos + 1 < len ? str[pos + 1] : 0; |
| 909 | |
| 910 | // Check for newlines |
| 911 | if (c == '\n' || c == '\r') |
| 912 | { |
| 913 | if (state != ParseState::IN_MULTI_LINE_COMMENT) |
| 914 | { |
| 915 | state = ParseState::BEGINING_OF_LINE; |
| 916 | } |
| 917 | |
| 918 | pos++; |
| 919 | continue; |
| 920 | } |
| 921 | |
| 922 | switch (state) |
| 923 | { |
| 924 | case ParseState::BEGINING_OF_LINE: |
| 925 | if (c == ' ') |
| 926 | { |
| 927 | // Maintain the BEGINING_OF_LINE state until a non-space is seen |
| 928 | pos++; |
| 929 | } |
| 930 | else if (c == '#') |
| 931 | { |
| 932 | state = ParseState::IN_PREPROCESSOR_DIRECTIVE; |
| 933 | pos++; |
| 934 | } |
| 935 | else |
| 936 | { |
| 937 | // Don't advance, re-process this character with the MIDDLE_OF_LINE state |
| 938 | state = ParseState::MIDDLE_OF_LINE; |
| 939 | } |
| 940 | break; |
| 941 | |
| 942 | case ParseState::MIDDLE_OF_LINE: |
| 943 | if (c == '/' && next == '/') |
| 944 | { |
| 945 | state = ParseState::IN_SINGLE_LINE_COMMENT; |
| 946 | pos++; |
| 947 | } |
| 948 | else if (c == '/' && next == '*') |
| 949 | { |
| 950 | state = ParseState::IN_MULTI_LINE_COMMENT; |
| 951 | pos++; |
| 952 | } |
| 953 | else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r')) |
| 954 | { |
| 955 | // Skip line continuation characters |
| 956 | } |
| 957 | else if (!IsValidESSLCharacter(c)) |
| 958 | { |
| 959 | return false; |
| 960 | } |
| 961 | pos++; |
| 962 | break; |
| 963 | |
| 964 | case ParseState::IN_PREPROCESSOR_DIRECTIVE: |
Bryan Bernhart (Intel Americas Inc) | 335d8bf | 2017-10-23 15:41:43 -0700 | [diff] [blame] | 965 | // Line-continuation characters may not be permitted. |
| 966 | // Otherwise, just pass it through. Do not parse comments in this state. |
| 967 | if (!lineContinuationAllowed && c == '\\') |
| 968 | { |
| 969 | return false; |
| 970 | } |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 971 | pos++; |
| 972 | break; |
| 973 | |
| 974 | case ParseState::IN_SINGLE_LINE_COMMENT: |
| 975 | // Line-continuation characters are processed before comment processing. |
| 976 | // Advance string if a new line character is immediately behind |
| 977 | // line-continuation character. |
| 978 | if (c == '\\' && (next == '\n' || next == '\r')) |
| 979 | { |
| 980 | pos++; |
| 981 | } |
| 982 | pos++; |
| 983 | break; |
| 984 | |
| 985 | case ParseState::IN_MULTI_LINE_COMMENT: |
| 986 | if (c == '*' && next == '/') |
| 987 | { |
| 988 | state = ParseState::MIDDLE_OF_LINE; |
| 989 | pos++; |
| 990 | } |
| 991 | pos++; |
| 992 | break; |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | return true; |
| 997 | } |
| 998 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 999 | bool ValidateWebGLNamePrefix(Context *context, const GLchar *name) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1000 | { |
| 1001 | ASSERT(context->isWebGL()); |
| 1002 | |
| 1003 | // WebGL 1.0 [Section 6.16] GLSL Constructs |
| 1004 | // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. |
| 1005 | if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0) |
| 1006 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1007 | context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1008 | return false; |
| 1009 | } |
| 1010 | |
| 1011 | return true; |
| 1012 | } |
| 1013 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1014 | bool ValidateWebGLNameLength(Context *context, size_t length) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1015 | { |
| 1016 | ASSERT(context->isWebGL()); |
| 1017 | |
| 1018 | if (context->isWebGL1() && length > 256) |
| 1019 | { |
| 1020 | // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths |
| 1021 | // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute |
| 1022 | // locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1023 | context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1024 | |
| 1025 | return false; |
| 1026 | } |
| 1027 | else if (length > 1024) |
| 1028 | { |
| 1029 | // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of |
| 1030 | // uniform and attribute locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1031 | context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | return true; |
| 1036 | } |
| 1037 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1038 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 1039 | { |
| 1040 | if (!context->getExtensions().pathRendering) |
| 1041 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1042 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1043 | return false; |
| 1044 | } |
| 1045 | |
| 1046 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 1047 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1048 | context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1049 | return false; |
| 1050 | } |
| 1051 | return true; |
| 1052 | } |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 1053 | |
| 1054 | bool ValidBlendFunc(const Context *context, GLenum val) |
| 1055 | { |
| 1056 | const gl::Extensions &ext = context->getExtensions(); |
| 1057 | |
| 1058 | // these are always valid for src and dst. |
| 1059 | switch (val) |
| 1060 | { |
| 1061 | case GL_ZERO: |
| 1062 | case GL_ONE: |
| 1063 | case GL_SRC_COLOR: |
| 1064 | case GL_ONE_MINUS_SRC_COLOR: |
| 1065 | case GL_DST_COLOR: |
| 1066 | case GL_ONE_MINUS_DST_COLOR: |
| 1067 | case GL_SRC_ALPHA: |
| 1068 | case GL_ONE_MINUS_SRC_ALPHA: |
| 1069 | case GL_DST_ALPHA: |
| 1070 | case GL_ONE_MINUS_DST_ALPHA: |
| 1071 | case GL_CONSTANT_COLOR: |
| 1072 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 1073 | case GL_CONSTANT_ALPHA: |
| 1074 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 1075 | return true; |
| 1076 | |
| 1077 | // EXT_blend_func_extended. |
| 1078 | case GL_SRC1_COLOR_EXT: |
| 1079 | case GL_SRC1_ALPHA_EXT: |
| 1080 | case GL_ONE_MINUS_SRC1_COLOR_EXT: |
| 1081 | case GL_ONE_MINUS_SRC1_ALPHA_EXT: |
| 1082 | case GL_SRC_ALPHA_SATURATE_EXT: |
| 1083 | return ext.blendFuncExtended; |
| 1084 | |
| 1085 | default: |
| 1086 | return false; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | bool ValidSrcBlendFunc(const Context *context, GLenum val) |
| 1091 | { |
| 1092 | if (ValidBlendFunc(context, val)) |
| 1093 | return true; |
| 1094 | |
| 1095 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1096 | return true; |
| 1097 | |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | bool ValidDstBlendFunc(const Context *context, GLenum val) |
| 1102 | { |
| 1103 | if (ValidBlendFunc(context, val)) |
| 1104 | return true; |
| 1105 | |
| 1106 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1107 | { |
| 1108 | if (context->getClientMajorVersion() >= 3) |
| 1109 | return true; |
| 1110 | } |
| 1111 | |
| 1112 | return false; |
| 1113 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1114 | } // anonymous namespace |
| 1115 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1116 | bool ValidateES2TexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1117 | TextureTarget target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1118 | GLint level, |
| 1119 | GLenum internalformat, |
| 1120 | bool isCompressed, |
| 1121 | bool isSubImage, |
| 1122 | GLint xoffset, |
| 1123 | GLint yoffset, |
| 1124 | GLsizei width, |
| 1125 | GLsizei height, |
| 1126 | GLint border, |
| 1127 | GLenum format, |
| 1128 | GLenum type, |
| 1129 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1130 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1131 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1132 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1133 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1134 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1135 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1138 | TextureType texType = TextureTargetToType(target); |
| 1139 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1140 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1141 | // Error already handled. |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1142 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1145 | if (!ValidMipLevel(context, texType, level)) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1146 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1147 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1148 | return false; |
| 1149 | } |
| 1150 | |
| 1151 | if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width || |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1152 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1153 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1154 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1155 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1156 | } |
| 1157 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1158 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 1159 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 1160 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 1161 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 1162 | // case. |
| 1163 | bool nonEqualFormatsAllowed = |
| 1164 | (internalformat == GL_RGB32F && context->getExtensions().colorBufferFloatRGB) || |
| 1165 | (internalformat == GL_RGBA32F && context->getExtensions().colorBufferFloatRGBA); |
| 1166 | |
| 1167 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1168 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1169 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1170 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1173 | const gl::Caps &caps = context->getCaps(); |
| 1174 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1175 | switch (texType) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1176 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1177 | case TextureType::_2D: |
| 1178 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 1179 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 1180 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1181 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1182 | return false; |
| 1183 | } |
| 1184 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1185 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1186 | case TextureType::Rectangle: |
| 1187 | ASSERT(level == 0); |
| 1188 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1189 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1190 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1191 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1192 | return false; |
| 1193 | } |
| 1194 | if (isCompressed) |
| 1195 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1196 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1197 | return false; |
| 1198 | } |
| 1199 | break; |
| 1200 | |
| 1201 | case TextureType::CubeMap: |
| 1202 | if (!isSubImage && width != height) |
| 1203 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1204 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1205 | return false; |
| 1206 | } |
| 1207 | |
| 1208 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 1209 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 1210 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1211 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1212 | return false; |
| 1213 | } |
| 1214 | break; |
| 1215 | |
| 1216 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1217 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1218 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1219 | } |
| 1220 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1221 | gl::Texture *texture = context->getTargetTexture(texType); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1222 | if (!texture) |
| 1223 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1224 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1225 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1228 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1229 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1230 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 1231 | if (textureInternalFormat.internalFormat == GL_NONE) |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1232 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1233 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureLevel); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1234 | return false; |
| 1235 | } |
| 1236 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1237 | if (format != GL_NONE) |
| 1238 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1239 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 1240 | textureInternalFormat.sizedInternalFormat) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1241 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1242 | context->validationError(GL_INVALID_OPERATION, kTypeMismatch); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1243 | return false; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1248 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 1249 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1250 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1251 | return false; |
| 1252 | } |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1253 | |
| 1254 | if (width > 0 && height > 0 && pixels == nullptr && |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1255 | context->getState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr) |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1256 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1257 | context->validationError(GL_INVALID_VALUE, kPixelDataNull); |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1258 | return false; |
| 1259 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1260 | } |
| 1261 | else |
| 1262 | { |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1263 | if (texture->getImmutableFormat()) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1264 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1265 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1266 | return false; |
| 1267 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | // Verify zero border |
| 1271 | if (border != 0) |
| 1272 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1273 | context->validationError(GL_INVALID_VALUE, kInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1274 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1275 | } |
| 1276 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1277 | if (isCompressed) |
| 1278 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1279 | GLenum actualInternalFormat = |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1280 | isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat |
| 1281 | : internalformat; |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1282 | |
| 1283 | const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat); |
| 1284 | |
| 1285 | if (!internalFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1286 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1287 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1288 | return false; |
| 1289 | } |
| 1290 | |
| 1291 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), |
| 1292 | context->getExtensions())) |
| 1293 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1294 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1295 | return false; |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1296 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1297 | |
| 1298 | if (isSubImage) |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1299 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1300 | // From the OES_compressed_ETC1_RGB8_texture spec: |
| 1301 | // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or |
| 1302 | // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format |
| 1303 | // ETC1_RGB8_OES. |
| 1304 | if (actualInternalFormat == GL_ETC1_RGB8_OES) |
| 1305 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1306 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1307 | return false; |
| 1308 | } |
| 1309 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1310 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width, |
| 1311 | height, texture->getWidth(target, level), |
| 1312 | texture->getHeight(target, level))) |
| 1313 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1314 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1315 | return false; |
| 1316 | } |
| 1317 | |
| 1318 | if (format != actualInternalFormat) |
| 1319 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1320 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1321 | return false; |
| 1322 | } |
| 1323 | } |
| 1324 | else |
| 1325 | { |
| 1326 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 1327 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1328 | context->validationError(GL_INVALID_OPERATION, kInvalidCompressedImageSize); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1329 | return false; |
| 1330 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | else |
| 1334 | { |
| 1335 | // validate <type> by itself (used as secondary key below) |
| 1336 | switch (type) |
| 1337 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1338 | case GL_UNSIGNED_BYTE: |
| 1339 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1340 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1341 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1342 | case GL_UNSIGNED_SHORT: |
| 1343 | case GL_UNSIGNED_INT: |
| 1344 | case GL_UNSIGNED_INT_24_8_OES: |
| 1345 | case GL_HALF_FLOAT_OES: |
| 1346 | case GL_FLOAT: |
| 1347 | break; |
| 1348 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1349 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1350 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | // validate <format> + <type> combinations |
| 1354 | // - invalid <format> -> sets INVALID_ENUM |
| 1355 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1356 | switch (format) |
| 1357 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1358 | case GL_ALPHA: |
| 1359 | case GL_LUMINANCE: |
| 1360 | case GL_LUMINANCE_ALPHA: |
| 1361 | switch (type) |
| 1362 | { |
| 1363 | case GL_UNSIGNED_BYTE: |
| 1364 | case GL_FLOAT: |
| 1365 | case GL_HALF_FLOAT_OES: |
| 1366 | break; |
| 1367 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1368 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1369 | return false; |
| 1370 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1371 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1372 | case GL_RED: |
| 1373 | case GL_RG: |
| 1374 | if (!context->getExtensions().textureRG) |
| 1375 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1376 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1377 | return false; |
| 1378 | } |
| 1379 | switch (type) |
| 1380 | { |
| 1381 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1382 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1383 | case GL_FLOAT: |
| 1384 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1385 | if (!context->getExtensions().textureFloat) |
| 1386 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1387 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1388 | return false; |
| 1389 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1390 | break; |
| 1391 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1392 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1393 | return false; |
| 1394 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1395 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1396 | case GL_RGB: |
| 1397 | switch (type) |
| 1398 | { |
| 1399 | case GL_UNSIGNED_BYTE: |
| 1400 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1401 | case GL_FLOAT: |
| 1402 | case GL_HALF_FLOAT_OES: |
| 1403 | break; |
| 1404 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1405 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1406 | return false; |
| 1407 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1408 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1409 | case GL_RGBA: |
| 1410 | switch (type) |
| 1411 | { |
| 1412 | case GL_UNSIGNED_BYTE: |
| 1413 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1414 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1415 | case GL_FLOAT: |
| 1416 | case GL_HALF_FLOAT_OES: |
| 1417 | break; |
| 1418 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1419 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1420 | return false; |
| 1421 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1422 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1423 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1424 | if (!context->getExtensions().textureFormatBGRA8888) |
| 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 | switch (type) |
| 1430 | { |
| 1431 | case GL_UNSIGNED_BYTE: |
| 1432 | break; |
| 1433 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1434 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1435 | return false; |
| 1436 | } |
| 1437 | break; |
| 1438 | case GL_SRGB_EXT: |
| 1439 | case GL_SRGB_ALPHA_EXT: |
| 1440 | if (!context->getExtensions().sRGB) |
| 1441 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1442 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1443 | return false; |
| 1444 | } |
| 1445 | switch (type) |
| 1446 | { |
| 1447 | case GL_UNSIGNED_BYTE: |
| 1448 | break; |
| 1449 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1450 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1451 | return false; |
| 1452 | } |
| 1453 | break; |
| 1454 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1455 | // handled below |
| 1456 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1457 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1458 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1459 | break; |
| 1460 | case GL_DEPTH_COMPONENT: |
| 1461 | switch (type) |
| 1462 | { |
| 1463 | case GL_UNSIGNED_SHORT: |
| 1464 | case GL_UNSIGNED_INT: |
| 1465 | break; |
| 1466 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1467 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1468 | return false; |
| 1469 | } |
| 1470 | break; |
| 1471 | case GL_DEPTH_STENCIL_OES: |
| 1472 | switch (type) |
| 1473 | { |
| 1474 | case GL_UNSIGNED_INT_24_8_OES: |
| 1475 | break; |
| 1476 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1477 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1478 | return false; |
| 1479 | } |
| 1480 | break; |
| 1481 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1482 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1483 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | switch (format) |
| 1487 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1488 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1489 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1490 | if (context->getExtensions().textureCompressionDXT1) |
| 1491 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1492 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1493 | return false; |
| 1494 | } |
| 1495 | else |
| 1496 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1497 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1498 | return false; |
| 1499 | } |
| 1500 | break; |
| 1501 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1502 | if (context->getExtensions().textureCompressionDXT3) |
| 1503 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1504 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1505 | return false; |
| 1506 | } |
| 1507 | else |
| 1508 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1509 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1510 | return false; |
| 1511 | } |
| 1512 | break; |
| 1513 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1514 | if (context->getExtensions().textureCompressionDXT5) |
| 1515 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1516 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1517 | return false; |
| 1518 | } |
| 1519 | else |
| 1520 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1521 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1522 | return false; |
| 1523 | } |
| 1524 | break; |
| 1525 | case GL_ETC1_RGB8_OES: |
| 1526 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1527 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1528 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1529 | return false; |
| 1530 | } |
| 1531 | else |
| 1532 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1533 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1534 | return false; |
| 1535 | } |
| 1536 | break; |
| 1537 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1538 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1539 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1540 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1541 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1542 | if (context->getExtensions().lossyETCDecode) |
| 1543 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1544 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1545 | return false; |
| 1546 | } |
| 1547 | else |
| 1548 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1549 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1550 | return false; |
| 1551 | } |
| 1552 | break; |
| 1553 | case GL_DEPTH_COMPONENT: |
| 1554 | case GL_DEPTH_STENCIL_OES: |
| 1555 | if (!context->getExtensions().depthTextures) |
| 1556 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1557 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1558 | return false; |
| 1559 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1560 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1561 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1562 | context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1563 | return false; |
| 1564 | } |
| 1565 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1566 | // but ANGLE_depth_texture does not |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1567 | if (pixels != nullptr) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1568 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1569 | context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull); |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1570 | return false; |
| 1571 | } |
| 1572 | if (level != 0) |
| 1573 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1574 | context->validationError(GL_INVALID_OPERATION, kLevelNotZero); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1575 | return false; |
| 1576 | } |
| 1577 | break; |
| 1578 | default: |
| 1579 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1580 | } |
| 1581 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1582 | if (!isSubImage) |
| 1583 | { |
| 1584 | switch (internalformat) |
| 1585 | { |
| 1586 | case GL_RGBA32F: |
| 1587 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1588 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1589 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1590 | return false; |
| 1591 | } |
| 1592 | if (type != GL_FLOAT) |
| 1593 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1594 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1595 | return false; |
| 1596 | } |
| 1597 | if (format != GL_RGBA) |
| 1598 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1599 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1600 | return false; |
| 1601 | } |
| 1602 | break; |
| 1603 | |
| 1604 | case GL_RGB32F: |
| 1605 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1606 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1607 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1608 | return false; |
| 1609 | } |
| 1610 | if (type != GL_FLOAT) |
| 1611 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1612 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1613 | return false; |
| 1614 | } |
| 1615 | if (format != GL_RGB) |
| 1616 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1617 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1618 | return false; |
| 1619 | } |
| 1620 | break; |
| 1621 | |
| 1622 | default: |
| 1623 | break; |
| 1624 | } |
| 1625 | } |
| 1626 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1627 | if (type == GL_FLOAT) |
| 1628 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1629 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1630 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1631 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1632 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1633 | } |
| 1634 | } |
| 1635 | else if (type == GL_HALF_FLOAT_OES) |
| 1636 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1637 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1638 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1639 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1640 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1641 | } |
| 1642 | } |
| 1643 | } |
| 1644 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 1645 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1646 | if (!ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1647 | imageSize)) |
| 1648 | { |
| 1649 | return false; |
| 1650 | } |
| 1651 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1652 | return true; |
| 1653 | } |
| 1654 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1655 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1656 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1657 | GLsizei levels, |
| 1658 | GLenum internalformat, |
| 1659 | GLsizei width, |
| 1660 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1661 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1662 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1663 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1664 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1665 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1666 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | if (width < 1 || height < 1 || levels < 1) |
| 1670 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1671 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1672 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1673 | } |
| 1674 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1675 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1676 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1677 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1678 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1682 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1683 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1684 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1685 | } |
| 1686 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1687 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1688 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1689 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1690 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1691 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1692 | } |
| 1693 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1694 | const gl::Caps &caps = context->getCaps(); |
| 1695 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1696 | switch (target) |
| 1697 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1698 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1699 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1700 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1701 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1702 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1703 | return false; |
| 1704 | } |
| 1705 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1706 | case TextureType::Rectangle: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1707 | if (levels != 1) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1708 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1709 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1710 | return false; |
| 1711 | } |
| 1712 | |
| 1713 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1714 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1715 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1716 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1717 | return false; |
| 1718 | } |
| 1719 | if (formatInfo.compressed) |
| 1720 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1721 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1722 | return false; |
| 1723 | } |
| 1724 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1725 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1726 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1727 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1728 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1729 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1730 | return false; |
| 1731 | } |
| 1732 | break; |
| 1733 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1734 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1735 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1736 | } |
| 1737 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1738 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1739 | { |
| 1740 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1741 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1742 | context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1743 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | switch (internalformat) |
| 1748 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1749 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1750 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1751 | if (!context->getExtensions().textureCompressionDXT1) |
| 1752 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1753 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1754 | return false; |
| 1755 | } |
| 1756 | break; |
| 1757 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1758 | if (!context->getExtensions().textureCompressionDXT3) |
| 1759 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1760 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1761 | return false; |
| 1762 | } |
| 1763 | break; |
| 1764 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1765 | if (!context->getExtensions().textureCompressionDXT5) |
| 1766 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1767 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1768 | return false; |
| 1769 | } |
| 1770 | break; |
| 1771 | case GL_ETC1_RGB8_OES: |
| 1772 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1773 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1774 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1775 | return false; |
| 1776 | } |
| 1777 | break; |
| 1778 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1779 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1780 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1781 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1782 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1783 | if (!context->getExtensions().lossyETCDecode) |
| 1784 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1785 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1786 | return false; |
| 1787 | } |
| 1788 | break; |
| 1789 | case GL_RGBA32F_EXT: |
| 1790 | case GL_RGB32F_EXT: |
| 1791 | case GL_ALPHA32F_EXT: |
| 1792 | case GL_LUMINANCE32F_EXT: |
| 1793 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1794 | if (!context->getExtensions().textureFloat) |
| 1795 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1796 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1797 | return false; |
| 1798 | } |
| 1799 | break; |
| 1800 | case GL_RGBA16F_EXT: |
| 1801 | case GL_RGB16F_EXT: |
| 1802 | case GL_ALPHA16F_EXT: |
| 1803 | case GL_LUMINANCE16F_EXT: |
| 1804 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1805 | if (!context->getExtensions().textureHalfFloat) |
| 1806 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1807 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1808 | return false; |
| 1809 | } |
| 1810 | break; |
| 1811 | case GL_R8_EXT: |
| 1812 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1813 | if (!context->getExtensions().textureRG) |
| 1814 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1815 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1816 | return false; |
| 1817 | } |
| 1818 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1819 | case GL_R16F_EXT: |
| 1820 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1821 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1822 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1823 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1824 | return false; |
| 1825 | } |
| 1826 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1827 | case GL_R32F_EXT: |
| 1828 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1829 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1830 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1831 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1832 | return false; |
| 1833 | } |
| 1834 | break; |
| 1835 | case GL_DEPTH_COMPONENT16: |
| 1836 | case GL_DEPTH_COMPONENT32_OES: |
| 1837 | case GL_DEPTH24_STENCIL8_OES: |
| 1838 | if (!context->getExtensions().depthTextures) |
| 1839 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1840 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1841 | return false; |
| 1842 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1843 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1844 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1845 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1846 | return false; |
| 1847 | } |
| 1848 | // ANGLE_depth_texture only supports 1-level textures |
| 1849 | if (levels != 1) |
| 1850 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1851 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1852 | return false; |
| 1853 | } |
| 1854 | break; |
| 1855 | default: |
| 1856 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1857 | } |
| 1858 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1859 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1860 | if (!texture || texture->id() == 0) |
| 1861 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1862 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1863 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1864 | } |
| 1865 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1866 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1867 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1868 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1869 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | return true; |
| 1873 | } |
| 1874 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1875 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 1876 | GLenum target, |
| 1877 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1878 | const GLenum *attachments) |
| 1879 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1880 | if (!context->getExtensions().discardFramebuffer) |
| 1881 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1882 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1883 | return false; |
| 1884 | } |
| 1885 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1886 | bool defaultFramebuffer = false; |
| 1887 | |
| 1888 | switch (target) |
| 1889 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1890 | case GL_FRAMEBUFFER: |
| 1891 | defaultFramebuffer = |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1892 | (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1893 | break; |
| 1894 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1895 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1896 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1899 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1900 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1903 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 1904 | { |
| 1905 | if (!context->getExtensions().vertexArrayObject) |
| 1906 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1907 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1908 | return false; |
| 1909 | } |
| 1910 | |
| 1911 | return ValidateBindVertexArrayBase(context, array); |
| 1912 | } |
| 1913 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1914 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1915 | { |
| 1916 | if (!context->getExtensions().vertexArrayObject) |
| 1917 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1918 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1919 | return false; |
| 1920 | } |
| 1921 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1922 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1925 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1926 | { |
| 1927 | if (!context->getExtensions().vertexArrayObject) |
| 1928 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1929 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1930 | return false; |
| 1931 | } |
| 1932 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1933 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1936 | bool ValidateIsVertexArrayOES(Context *context, GLuint array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1937 | { |
| 1938 | if (!context->getExtensions().vertexArrayObject) |
| 1939 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1940 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1941 | return false; |
| 1942 | } |
| 1943 | |
| 1944 | return true; |
| 1945 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1946 | |
| 1947 | bool ValidateProgramBinaryOES(Context *context, |
| 1948 | GLuint program, |
| 1949 | GLenum binaryFormat, |
| 1950 | const void *binary, |
| 1951 | GLint length) |
| 1952 | { |
| 1953 | if (!context->getExtensions().getProgramBinary) |
| 1954 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1955 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1956 | return false; |
| 1957 | } |
| 1958 | |
| 1959 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1960 | } |
| 1961 | |
| 1962 | bool ValidateGetProgramBinaryOES(Context *context, |
| 1963 | GLuint program, |
| 1964 | GLsizei bufSize, |
| 1965 | GLsizei *length, |
| 1966 | GLenum *binaryFormat, |
| 1967 | void *binary) |
| 1968 | { |
| 1969 | if (!context->getExtensions().getProgramBinary) |
| 1970 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1971 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1972 | return false; |
| 1973 | } |
| 1974 | |
| 1975 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1976 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1977 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1978 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 1979 | { |
| 1980 | switch (source) |
| 1981 | { |
| 1982 | case GL_DEBUG_SOURCE_API: |
| 1983 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 1984 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 1985 | case GL_DEBUG_SOURCE_OTHER: |
| 1986 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 1987 | return !mustBeThirdPartyOrApplication; |
| 1988 | |
| 1989 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 1990 | case GL_DEBUG_SOURCE_APPLICATION: |
| 1991 | return true; |
| 1992 | |
| 1993 | default: |
| 1994 | return false; |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | static bool ValidDebugType(GLenum type) |
| 1999 | { |
| 2000 | switch (type) |
| 2001 | { |
| 2002 | case GL_DEBUG_TYPE_ERROR: |
| 2003 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 2004 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 2005 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 2006 | case GL_DEBUG_TYPE_PORTABILITY: |
| 2007 | case GL_DEBUG_TYPE_OTHER: |
| 2008 | case GL_DEBUG_TYPE_MARKER: |
| 2009 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 2010 | case GL_DEBUG_TYPE_POP_GROUP: |
| 2011 | return true; |
| 2012 | |
| 2013 | default: |
| 2014 | return false; |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | static bool ValidDebugSeverity(GLenum severity) |
| 2019 | { |
| 2020 | switch (severity) |
| 2021 | { |
| 2022 | case GL_DEBUG_SEVERITY_HIGH: |
| 2023 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 2024 | case GL_DEBUG_SEVERITY_LOW: |
| 2025 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 2026 | return true; |
| 2027 | |
| 2028 | default: |
| 2029 | return false; |
| 2030 | } |
| 2031 | } |
| 2032 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2033 | bool ValidateDebugMessageControlKHR(Context *context, |
| 2034 | GLenum source, |
| 2035 | GLenum type, |
| 2036 | GLenum severity, |
| 2037 | GLsizei count, |
| 2038 | const GLuint *ids, |
| 2039 | GLboolean enabled) |
| 2040 | { |
| 2041 | if (!context->getExtensions().debug) |
| 2042 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2043 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2044 | return false; |
| 2045 | } |
| 2046 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2047 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 2048 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2049 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2050 | return false; |
| 2051 | } |
| 2052 | |
| 2053 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 2054 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2055 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2056 | return false; |
| 2057 | } |
| 2058 | |
| 2059 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 2060 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2061 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2062 | return false; |
| 2063 | } |
| 2064 | |
| 2065 | if (count > 0) |
| 2066 | { |
| 2067 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2068 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2069 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSourceType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2070 | return false; |
| 2071 | } |
| 2072 | |
| 2073 | if (severity != GL_DONT_CARE) |
| 2074 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2075 | context->validationError(GL_INVALID_OPERATION, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2076 | return false; |
| 2077 | } |
| 2078 | } |
| 2079 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2080 | return true; |
| 2081 | } |
| 2082 | |
| 2083 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2084 | GLenum source, |
| 2085 | GLenum type, |
| 2086 | GLuint id, |
| 2087 | GLenum severity, |
| 2088 | GLsizei length, |
| 2089 | const GLchar *buf) |
| 2090 | { |
| 2091 | if (!context->getExtensions().debug) |
| 2092 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2093 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2094 | return false; |
| 2095 | } |
| 2096 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2097 | if (!context->getState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2098 | { |
| 2099 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2100 | // not generate an error. |
| 2101 | return false; |
| 2102 | } |
| 2103 | |
| 2104 | if (!ValidDebugSeverity(severity)) |
| 2105 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2106 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2107 | return false; |
| 2108 | } |
| 2109 | |
| 2110 | if (!ValidDebugType(type)) |
| 2111 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2112 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2113 | return false; |
| 2114 | } |
| 2115 | |
| 2116 | if (!ValidDebugSource(source, true)) |
| 2117 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2118 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2119 | return false; |
| 2120 | } |
| 2121 | |
| 2122 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2123 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2124 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2125 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2126 | return false; |
| 2127 | } |
| 2128 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2129 | return true; |
| 2130 | } |
| 2131 | |
| 2132 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2133 | GLDEBUGPROCKHR callback, |
| 2134 | const void *userParam) |
| 2135 | { |
| 2136 | if (!context->getExtensions().debug) |
| 2137 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2138 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2139 | return false; |
| 2140 | } |
| 2141 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2142 | return true; |
| 2143 | } |
| 2144 | |
| 2145 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2146 | GLuint count, |
| 2147 | GLsizei bufSize, |
| 2148 | GLenum *sources, |
| 2149 | GLenum *types, |
| 2150 | GLuint *ids, |
| 2151 | GLenum *severities, |
| 2152 | GLsizei *lengths, |
| 2153 | GLchar *messageLog) |
| 2154 | { |
| 2155 | if (!context->getExtensions().debug) |
| 2156 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2157 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2158 | return false; |
| 2159 | } |
| 2160 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2161 | if (bufSize < 0 && messageLog != nullptr) |
| 2162 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2163 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2164 | return false; |
| 2165 | } |
| 2166 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2167 | return true; |
| 2168 | } |
| 2169 | |
| 2170 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2171 | GLenum source, |
| 2172 | GLuint id, |
| 2173 | GLsizei length, |
| 2174 | const GLchar *message) |
| 2175 | { |
| 2176 | if (!context->getExtensions().debug) |
| 2177 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2178 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2179 | return false; |
| 2180 | } |
| 2181 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2182 | if (!ValidDebugSource(source, true)) |
| 2183 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2184 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2185 | return false; |
| 2186 | } |
| 2187 | |
| 2188 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2189 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2190 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2191 | context->validationError(GL_INVALID_VALUE, kExceedsMaxDebugMessageLength); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2192 | return false; |
| 2193 | } |
| 2194 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2195 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2196 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2197 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2198 | context->validationError(GL_STACK_OVERFLOW, kExceedsMaxDebugGroupStackDepth); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2199 | return false; |
| 2200 | } |
| 2201 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2202 | return true; |
| 2203 | } |
| 2204 | |
| 2205 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2206 | { |
| 2207 | if (!context->getExtensions().debug) |
| 2208 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2209 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2210 | return false; |
| 2211 | } |
| 2212 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2213 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2214 | if (currentStackSize <= 1) |
| 2215 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2216 | context->validationError(GL_STACK_UNDERFLOW, kCannotPopDefaultDebugGroup); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2217 | return false; |
| 2218 | } |
| 2219 | |
| 2220 | return true; |
| 2221 | } |
| 2222 | |
| 2223 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2224 | { |
| 2225 | switch (identifier) |
| 2226 | { |
| 2227 | case GL_BUFFER: |
| 2228 | if (context->getBuffer(name) == nullptr) |
| 2229 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2230 | context->validationError(GL_INVALID_VALUE, kInvalidBufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2231 | return false; |
| 2232 | } |
| 2233 | return true; |
| 2234 | |
| 2235 | case GL_SHADER: |
| 2236 | if (context->getShader(name) == nullptr) |
| 2237 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2238 | context->validationError(GL_INVALID_VALUE, kInvalidShaderName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2239 | return false; |
| 2240 | } |
| 2241 | return true; |
| 2242 | |
| 2243 | case GL_PROGRAM: |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2244 | if (context->getProgramNoResolveLink(name) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2245 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2246 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2247 | return false; |
| 2248 | } |
| 2249 | return true; |
| 2250 | |
| 2251 | case GL_VERTEX_ARRAY: |
| 2252 | if (context->getVertexArray(name) == nullptr) |
| 2253 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2254 | context->validationError(GL_INVALID_VALUE, kInvalidVertexArrayName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2255 | return false; |
| 2256 | } |
| 2257 | return true; |
| 2258 | |
| 2259 | case GL_QUERY: |
| 2260 | if (context->getQuery(name) == nullptr) |
| 2261 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2262 | context->validationError(GL_INVALID_VALUE, kInvalidQueryName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2263 | return false; |
| 2264 | } |
| 2265 | return true; |
| 2266 | |
| 2267 | case GL_TRANSFORM_FEEDBACK: |
| 2268 | if (context->getTransformFeedback(name) == nullptr) |
| 2269 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2270 | context->validationError(GL_INVALID_VALUE, kInvalidTransformFeedbackName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2271 | return false; |
| 2272 | } |
| 2273 | return true; |
| 2274 | |
| 2275 | case GL_SAMPLER: |
| 2276 | if (context->getSampler(name) == nullptr) |
| 2277 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2278 | context->validationError(GL_INVALID_VALUE, kInvalidSamplerName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2279 | return false; |
| 2280 | } |
| 2281 | return true; |
| 2282 | |
| 2283 | case GL_TEXTURE: |
| 2284 | if (context->getTexture(name) == nullptr) |
| 2285 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2286 | context->validationError(GL_INVALID_VALUE, kInvalidTextureName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2287 | return false; |
| 2288 | } |
| 2289 | return true; |
| 2290 | |
| 2291 | case GL_RENDERBUFFER: |
| 2292 | if (context->getRenderbuffer(name) == nullptr) |
| 2293 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2294 | context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2295 | return false; |
| 2296 | } |
| 2297 | return true; |
| 2298 | |
| 2299 | case GL_FRAMEBUFFER: |
| 2300 | if (context->getFramebuffer(name) == nullptr) |
| 2301 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2302 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferName); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2303 | return false; |
| 2304 | } |
| 2305 | return true; |
| 2306 | |
| 2307 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2308 | context->validationError(GL_INVALID_ENUM, kInvalidIndentifier); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2309 | return false; |
| 2310 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2311 | } |
| 2312 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2313 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2314 | { |
| 2315 | size_t labelLength = 0; |
| 2316 | |
| 2317 | if (length < 0) |
| 2318 | { |
| 2319 | if (label != nullptr) |
| 2320 | { |
| 2321 | labelLength = strlen(label); |
| 2322 | } |
| 2323 | } |
| 2324 | else |
| 2325 | { |
| 2326 | labelLength = static_cast<size_t>(length); |
| 2327 | } |
| 2328 | |
| 2329 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2330 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2331 | context->validationError(GL_INVALID_VALUE, kExceedsMaxLabelLength); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2332 | return false; |
| 2333 | } |
| 2334 | |
| 2335 | return true; |
| 2336 | } |
| 2337 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2338 | bool ValidateObjectLabelKHR(Context *context, |
| 2339 | GLenum identifier, |
| 2340 | GLuint name, |
| 2341 | GLsizei length, |
| 2342 | const GLchar *label) |
| 2343 | { |
| 2344 | if (!context->getExtensions().debug) |
| 2345 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2346 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2347 | return false; |
| 2348 | } |
| 2349 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2350 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2351 | { |
| 2352 | return false; |
| 2353 | } |
| 2354 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2355 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2356 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2357 | return false; |
| 2358 | } |
| 2359 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2360 | return true; |
| 2361 | } |
| 2362 | |
| 2363 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2364 | GLenum identifier, |
| 2365 | GLuint name, |
| 2366 | GLsizei bufSize, |
| 2367 | GLsizei *length, |
| 2368 | GLchar *label) |
| 2369 | { |
| 2370 | if (!context->getExtensions().debug) |
| 2371 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2372 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2373 | return false; |
| 2374 | } |
| 2375 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2376 | if (bufSize < 0) |
| 2377 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2378 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2379 | return false; |
| 2380 | } |
| 2381 | |
| 2382 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2383 | { |
| 2384 | return false; |
| 2385 | } |
| 2386 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2387 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2391 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2392 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2393 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2394 | context->validationError(GL_INVALID_VALUE, kInvalidSyncPointer); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2395 | return false; |
| 2396 | } |
| 2397 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2398 | return true; |
| 2399 | } |
| 2400 | |
| 2401 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2402 | const void *ptr, |
| 2403 | GLsizei length, |
| 2404 | const GLchar *label) |
| 2405 | { |
| 2406 | if (!context->getExtensions().debug) |
| 2407 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2408 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2409 | return false; |
| 2410 | } |
| 2411 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2412 | if (!ValidateObjectPtrName(context, ptr)) |
| 2413 | { |
| 2414 | return false; |
| 2415 | } |
| 2416 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2417 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2418 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2419 | return false; |
| 2420 | } |
| 2421 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2422 | return true; |
| 2423 | } |
| 2424 | |
| 2425 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2426 | const void *ptr, |
| 2427 | GLsizei bufSize, |
| 2428 | GLsizei *length, |
| 2429 | GLchar *label) |
| 2430 | { |
| 2431 | if (!context->getExtensions().debug) |
| 2432 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2433 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2434 | return false; |
| 2435 | } |
| 2436 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2437 | if (bufSize < 0) |
| 2438 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2439 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2440 | return false; |
| 2441 | } |
| 2442 | |
| 2443 | if (!ValidateObjectPtrName(context, ptr)) |
| 2444 | { |
| 2445 | return false; |
| 2446 | } |
| 2447 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2448 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2452 | { |
| 2453 | if (!context->getExtensions().debug) |
| 2454 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2455 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2456 | return false; |
| 2457 | } |
| 2458 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2459 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2460 | switch (pname) |
| 2461 | { |
| 2462 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2463 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2464 | break; |
| 2465 | |
| 2466 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2467 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2468 | return false; |
| 2469 | } |
| 2470 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2471 | return true; |
| 2472 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2473 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2474 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2475 | GLenum pname, |
| 2476 | GLsizei bufSize, |
| 2477 | GLsizei *length, |
| 2478 | void **params) |
| 2479 | { |
| 2480 | UNIMPLEMENTED(); |
| 2481 | return false; |
| 2482 | } |
| 2483 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2484 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2485 | GLint srcX0, |
| 2486 | GLint srcY0, |
| 2487 | GLint srcX1, |
| 2488 | GLint srcY1, |
| 2489 | GLint dstX0, |
| 2490 | GLint dstY0, |
| 2491 | GLint dstX1, |
| 2492 | GLint dstY1, |
| 2493 | GLbitfield mask, |
| 2494 | GLenum filter) |
| 2495 | { |
| 2496 | if (!context->getExtensions().framebufferBlit) |
| 2497 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2498 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2499 | return false; |
| 2500 | } |
| 2501 | |
| 2502 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2503 | { |
| 2504 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2505 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2506 | return false; |
| 2507 | } |
| 2508 | |
| 2509 | if (filter == GL_LINEAR) |
| 2510 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2511 | context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2512 | return false; |
| 2513 | } |
| 2514 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2515 | Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 2516 | Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2517 | |
| 2518 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2519 | { |
| 2520 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 2521 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 2522 | |
| 2523 | if (readColorAttachment && drawColorAttachment) |
| 2524 | { |
| 2525 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2526 | readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2527 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2528 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2529 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2530 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2531 | kBlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2532 | return false; |
| 2533 | } |
| 2534 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2535 | for (size_t drawbufferIdx = 0; |
| 2536 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2537 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2538 | const FramebufferAttachment *attachment = |
| 2539 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2540 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2541 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2542 | if (!(attachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2543 | attachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2544 | attachment->type() != GL_RENDERBUFFER && |
| 2545 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2546 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2547 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2548 | kBlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2549 | return false; |
| 2550 | } |
| 2551 | |
| 2552 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2553 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2554 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2555 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2556 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2557 | kBlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2558 | return false; |
| 2559 | } |
| 2560 | } |
| 2561 | } |
| 2562 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2563 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2564 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2565 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2566 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2567 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2568 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2569 | kBlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2570 | return false; |
| 2571 | } |
| 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2576 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2577 | for (size_t i = 0; i < 2; i++) |
| 2578 | { |
| 2579 | if (mask & masks[i]) |
| 2580 | { |
| 2581 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2582 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2583 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2584 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2585 | |
| 2586 | if (readBuffer && drawBuffer) |
| 2587 | { |
| 2588 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2589 | dstX0, dstY0, dstX1, dstY1)) |
| 2590 | { |
| 2591 | // only whole-buffer copies are permitted |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2592 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2593 | kBlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2594 | return false; |
| 2595 | } |
| 2596 | |
| 2597 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2598 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2599 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2600 | kBlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2601 | return false; |
| 2602 | } |
| 2603 | } |
| 2604 | } |
| 2605 | } |
| 2606 | |
| 2607 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2608 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2609 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2610 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2611 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2612 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2613 | Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2614 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2615 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2616 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2617 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2618 | return false; |
| 2619 | } |
| 2620 | |
| 2621 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2622 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2623 | context->validationError(GL_INVALID_VALUE, kInvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2624 | return false; |
| 2625 | } |
| 2626 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2627 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2628 | { |
| 2629 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2630 | GL_SIGNED_NORMALIZED}; |
| 2631 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2632 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2633 | drawBufferIdx++) |
| 2634 | { |
| 2635 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2636 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2637 | { |
| 2638 | return false; |
| 2639 | } |
| 2640 | } |
| 2641 | } |
| 2642 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2643 | if (extensions.multiview && extensions.disjointTimerQuery) |
| 2644 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2645 | const State &state = context->getState(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2646 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2647 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2648 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2649 | context->validationError(GL_INVALID_OPERATION, kMultiviewTimerQuery); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2650 | return false; |
| 2651 | } |
| 2652 | } |
| 2653 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2654 | return true; |
| 2655 | } |
| 2656 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2657 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2658 | { |
| 2659 | if (!context->getExtensions().drawBuffers) |
| 2660 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2661 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2662 | return false; |
| 2663 | } |
| 2664 | |
| 2665 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2666 | } |
| 2667 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2668 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2669 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2670 | GLint level, |
| 2671 | GLint internalformat, |
| 2672 | GLsizei width, |
| 2673 | GLsizei height, |
| 2674 | GLint border, |
| 2675 | GLenum format, |
| 2676 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2677 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2678 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2679 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2680 | { |
| 2681 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2682 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2683 | } |
| 2684 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2685 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2686 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2687 | 0, 0, width, height, 1, border, format, type, -1, |
| 2688 | pixels); |
| 2689 | } |
| 2690 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2691 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2692 | TextureTarget target, |
| 2693 | GLint level, |
| 2694 | GLint internalformat, |
| 2695 | GLsizei width, |
| 2696 | GLsizei height, |
| 2697 | GLint border, |
| 2698 | GLenum format, |
| 2699 | GLenum type, |
| 2700 | GLsizei bufSize, |
| 2701 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2702 | { |
| 2703 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2704 | { |
| 2705 | return false; |
| 2706 | } |
| 2707 | |
| 2708 | if (context->getClientMajorVersion() < 3) |
| 2709 | { |
| 2710 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2711 | 0, 0, width, height, border, format, type, bufSize, |
| 2712 | pixels); |
| 2713 | } |
| 2714 | |
| 2715 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2716 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2717 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2718 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2722 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2723 | GLint level, |
| 2724 | GLint xoffset, |
| 2725 | GLint yoffset, |
| 2726 | GLsizei width, |
| 2727 | GLsizei height, |
| 2728 | GLenum format, |
| 2729 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2730 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2731 | { |
| 2732 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2733 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2734 | { |
| 2735 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2736 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2737 | } |
| 2738 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2739 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2740 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2741 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2742 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2743 | } |
| 2744 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2745 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2746 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2747 | GLint level, |
| 2748 | GLint xoffset, |
| 2749 | GLint yoffset, |
| 2750 | GLsizei width, |
| 2751 | GLsizei height, |
| 2752 | GLenum format, |
| 2753 | GLenum type, |
| 2754 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2755 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2756 | { |
| 2757 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2758 | { |
| 2759 | return false; |
| 2760 | } |
| 2761 | |
| 2762 | if (context->getClientMajorVersion() < 3) |
| 2763 | { |
| 2764 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2765 | yoffset, width, height, 0, format, type, bufSize, |
| 2766 | pixels); |
| 2767 | } |
| 2768 | |
| 2769 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2770 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2771 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2772 | pixels); |
| 2773 | } |
| 2774 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2775 | bool ValidateCompressedTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2776 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2777 | GLint level, |
| 2778 | GLenum internalformat, |
| 2779 | GLsizei width, |
| 2780 | GLsizei height, |
| 2781 | GLint border, |
| 2782 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2783 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2784 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2785 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2786 | { |
| 2787 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2788 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2789 | { |
| 2790 | return false; |
| 2791 | } |
| 2792 | } |
| 2793 | else |
| 2794 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2795 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2796 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2797 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2798 | data)) |
| 2799 | { |
| 2800 | return false; |
| 2801 | } |
| 2802 | } |
| 2803 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2804 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2805 | |
| 2806 | GLuint blockSize = 0; |
| 2807 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2808 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2809 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2810 | return false; |
| 2811 | } |
| 2812 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2813 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2814 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2815 | context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2816 | return false; |
| 2817 | } |
| 2818 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2819 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2820 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2821 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2822 | return false; |
| 2823 | } |
| 2824 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2825 | return true; |
| 2826 | } |
| 2827 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2828 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2829 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2830 | GLint level, |
| 2831 | GLenum internalformat, |
| 2832 | GLsizei width, |
| 2833 | GLsizei height, |
| 2834 | GLint border, |
| 2835 | GLsizei imageSize, |
| 2836 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2837 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2838 | { |
| 2839 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2840 | { |
| 2841 | return false; |
| 2842 | } |
| 2843 | |
| 2844 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 2845 | border, imageSize, data); |
| 2846 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2847 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2848 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2849 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2850 | GLint level, |
| 2851 | GLint xoffset, |
| 2852 | GLint yoffset, |
| 2853 | GLsizei width, |
| 2854 | GLsizei height, |
| 2855 | GLenum format, |
| 2856 | GLsizei imageSize, |
| 2857 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2858 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2859 | { |
| 2860 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2861 | { |
| 2862 | return false; |
| 2863 | } |
| 2864 | |
| 2865 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 2866 | format, imageSize, data); |
| 2867 | } |
| 2868 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2869 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2870 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2871 | GLint level, |
| 2872 | GLint xoffset, |
| 2873 | GLint yoffset, |
| 2874 | GLsizei width, |
| 2875 | GLsizei height, |
| 2876 | GLenum format, |
| 2877 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2878 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2879 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2880 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2881 | { |
| 2882 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2883 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2884 | { |
| 2885 | return false; |
| 2886 | } |
| 2887 | } |
| 2888 | else |
| 2889 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2890 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2891 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2892 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2893 | data)) |
| 2894 | { |
| 2895 | return false; |
| 2896 | } |
| 2897 | } |
| 2898 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2899 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2900 | GLuint blockSize = 0; |
| 2901 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2902 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2903 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2904 | return false; |
| 2905 | } |
| 2906 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2907 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2908 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2909 | context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2910 | return false; |
| 2911 | } |
| 2912 | |
| 2913 | return true; |
| 2914 | } |
| 2915 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2916 | bool ValidateGetBufferPointervOES(Context *context, |
| 2917 | BufferBinding target, |
| 2918 | GLenum pname, |
| 2919 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2920 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2921 | if (!context->getExtensions().mapBuffer) |
| 2922 | { |
| 2923 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 2924 | return false; |
| 2925 | } |
| 2926 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2927 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2928 | } |
| 2929 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2930 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2931 | { |
| 2932 | if (!context->getExtensions().mapBuffer) |
| 2933 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2934 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2935 | return false; |
| 2936 | } |
| 2937 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 2938 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2939 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2940 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2941 | return false; |
| 2942 | } |
| 2943 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2944 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2945 | |
| 2946 | if (buffer == nullptr) |
| 2947 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2948 | context->validationError(GL_INVALID_OPERATION, kBufferNotMappable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2949 | return false; |
| 2950 | } |
| 2951 | |
| 2952 | if (access != GL_WRITE_ONLY_OES) |
| 2953 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2954 | context->validationError(GL_INVALID_ENUM, kInvalidAccessBits); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2955 | return false; |
| 2956 | } |
| 2957 | |
| 2958 | if (buffer->isMapped()) |
| 2959 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2960 | context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2961 | return false; |
| 2962 | } |
| 2963 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 2964 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2965 | } |
| 2966 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2967 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2968 | { |
| 2969 | if (!context->getExtensions().mapBuffer) |
| 2970 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2971 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2972 | return false; |
| 2973 | } |
| 2974 | |
| 2975 | return ValidateUnmapBufferBase(context, target); |
| 2976 | } |
| 2977 | |
| 2978 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2979 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2980 | GLintptr offset, |
| 2981 | GLsizeiptr length, |
| 2982 | GLbitfield access) |
| 2983 | { |
| 2984 | if (!context->getExtensions().mapBufferRange) |
| 2985 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2986 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2987 | return false; |
| 2988 | } |
| 2989 | |
| 2990 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 2991 | } |
| 2992 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2993 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 2994 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2995 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 2996 | ASSERT(buffer != nullptr); |
| 2997 | |
| 2998 | // 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] | 2999 | TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3000 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 3001 | { |
| 3002 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3003 | { |
| 3004 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3005 | if (transformFeedbackBuffer.get() == buffer) |
| 3006 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3007 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3008 | return false; |
| 3009 | } |
| 3010 | } |
| 3011 | } |
| 3012 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3013 | if (context->getExtensions().webglCompatibility && |
| 3014 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3015 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3016 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3017 | return false; |
| 3018 | } |
| 3019 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3020 | return true; |
| 3021 | } |
| 3022 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3023 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3024 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3025 | GLintptr offset, |
| 3026 | GLsizeiptr length) |
| 3027 | { |
| 3028 | if (!context->getExtensions().mapBufferRange) |
| 3029 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3030 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3031 | return false; |
| 3032 | } |
| 3033 | |
| 3034 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3035 | } |
| 3036 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3037 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 3038 | GLuint program, |
| 3039 | GLint location, |
| 3040 | const GLchar *name) |
| 3041 | { |
| 3042 | if (!context->getExtensions().bindUniformLocation) |
| 3043 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3044 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3045 | return false; |
| 3046 | } |
| 3047 | |
| 3048 | Program *programObject = GetValidProgram(context, program); |
| 3049 | if (!programObject) |
| 3050 | { |
| 3051 | return false; |
| 3052 | } |
| 3053 | |
| 3054 | if (location < 0) |
| 3055 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3056 | context->validationError(GL_INVALID_VALUE, kNegativeLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3057 | return false; |
| 3058 | } |
| 3059 | |
| 3060 | const Caps &caps = context->getCaps(); |
| 3061 | if (static_cast<size_t>(location) >= |
| 3062 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3063 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3064 | context->validationError(GL_INVALID_VALUE, kInvalidBindUniformLocation); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3065 | return false; |
| 3066 | } |
| 3067 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3068 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3069 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3070 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3071 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3072 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3073 | return false; |
| 3074 | } |
| 3075 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3076 | if (strncmp(name, "gl_", 3) == 0) |
| 3077 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3078 | context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3079 | return false; |
| 3080 | } |
| 3081 | |
| 3082 | return true; |
| 3083 | } |
| 3084 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3085 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3086 | { |
| 3087 | if (!context->getExtensions().framebufferMixedSamples) |
| 3088 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3089 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3090 | return false; |
| 3091 | } |
| 3092 | switch (components) |
| 3093 | { |
| 3094 | case GL_RGB: |
| 3095 | case GL_RGBA: |
| 3096 | case GL_ALPHA: |
| 3097 | case GL_NONE: |
| 3098 | break; |
| 3099 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3100 | context->validationError(GL_INVALID_ENUM, kInvalidCoverageComponents); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3101 | return false; |
| 3102 | } |
| 3103 | |
| 3104 | return true; |
| 3105 | } |
| 3106 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3107 | // CHROMIUM_path_rendering |
| 3108 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3109 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3110 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3111 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3112 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3113 | return false; |
| 3114 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3115 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3116 | if (matrix == nullptr) |
| 3117 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3118 | context->validationError(GL_INVALID_OPERATION, kInvalidPathMatrix); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3119 | return false; |
| 3120 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3121 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3122 | return true; |
| 3123 | } |
| 3124 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3125 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3126 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3127 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3128 | } |
| 3129 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3130 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3131 | { |
| 3132 | if (!context->getExtensions().pathRendering) |
| 3133 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3134 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3135 | return false; |
| 3136 | } |
| 3137 | |
| 3138 | // range = 0 is undefined in NV_path_rendering. |
| 3139 | // we add stricter semantic check here and require a non zero positive range. |
| 3140 | if (range <= 0) |
| 3141 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3142 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3143 | return false; |
| 3144 | } |
| 3145 | |
| 3146 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3147 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3148 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3149 | return false; |
| 3150 | } |
| 3151 | |
| 3152 | return true; |
| 3153 | } |
| 3154 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3155 | bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3156 | { |
| 3157 | if (!context->getExtensions().pathRendering) |
| 3158 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3159 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3160 | return false; |
| 3161 | } |
| 3162 | |
| 3163 | // range = 0 is undefined in NV_path_rendering. |
| 3164 | // we add stricter semantic check here and require a non zero positive range. |
| 3165 | if (range <= 0) |
| 3166 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3167 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3168 | return false; |
| 3169 | } |
| 3170 | |
| 3171 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 3172 | checkedRange += range; |
| 3173 | |
| 3174 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3175 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3176 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3177 | return false; |
| 3178 | } |
| 3179 | return true; |
| 3180 | } |
| 3181 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3182 | bool ValidatePathCommandsCHROMIUM(Context *context, |
| 3183 | GLuint path, |
| 3184 | GLsizei numCommands, |
| 3185 | const GLubyte *commands, |
| 3186 | GLsizei numCoords, |
| 3187 | GLenum coordType, |
| 3188 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3189 | { |
| 3190 | if (!context->getExtensions().pathRendering) |
| 3191 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3192 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3193 | return false; |
| 3194 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3195 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3196 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3197 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3198 | return false; |
| 3199 | } |
| 3200 | |
| 3201 | if (numCommands < 0) |
| 3202 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3203 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCommands); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3204 | return false; |
| 3205 | } |
| 3206 | else if (numCommands > 0) |
| 3207 | { |
| 3208 | if (!commands) |
| 3209 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3210 | context->validationError(GL_INVALID_VALUE, kInvalidPathCommandsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3211 | return false; |
| 3212 | } |
| 3213 | } |
| 3214 | |
| 3215 | if (numCoords < 0) |
| 3216 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3217 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3218 | return false; |
| 3219 | } |
| 3220 | else if (numCoords > 0) |
| 3221 | { |
| 3222 | if (!coords) |
| 3223 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3224 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoordsArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3225 | return false; |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | std::uint32_t coordTypeSize = 0; |
| 3230 | switch (coordType) |
| 3231 | { |
| 3232 | case GL_BYTE: |
| 3233 | coordTypeSize = sizeof(GLbyte); |
| 3234 | break; |
| 3235 | |
| 3236 | case GL_UNSIGNED_BYTE: |
| 3237 | coordTypeSize = sizeof(GLubyte); |
| 3238 | break; |
| 3239 | |
| 3240 | case GL_SHORT: |
| 3241 | coordTypeSize = sizeof(GLshort); |
| 3242 | break; |
| 3243 | |
| 3244 | case GL_UNSIGNED_SHORT: |
| 3245 | coordTypeSize = sizeof(GLushort); |
| 3246 | break; |
| 3247 | |
| 3248 | case GL_FLOAT: |
| 3249 | coordTypeSize = sizeof(GLfloat); |
| 3250 | break; |
| 3251 | |
| 3252 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3253 | context->validationError(GL_INVALID_ENUM, kInvalidPathCoordinateType); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3254 | return false; |
| 3255 | } |
| 3256 | |
| 3257 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3258 | checkedSize += (coordTypeSize * numCoords); |
| 3259 | if (!checkedSize.IsValid()) |
| 3260 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3261 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3262 | return false; |
| 3263 | } |
| 3264 | |
| 3265 | // early return skips command data validation when it doesn't exist. |
| 3266 | if (!commands) |
| 3267 | return true; |
| 3268 | |
| 3269 | GLsizei expectedNumCoords = 0; |
| 3270 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3271 | { |
| 3272 | switch (commands[i]) |
| 3273 | { |
| 3274 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3275 | break; |
| 3276 | case GL_MOVE_TO_CHROMIUM: |
| 3277 | case GL_LINE_TO_CHROMIUM: |
| 3278 | expectedNumCoords += 2; |
| 3279 | break; |
| 3280 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3281 | expectedNumCoords += 4; |
| 3282 | break; |
| 3283 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3284 | expectedNumCoords += 6; |
| 3285 | break; |
| 3286 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3287 | expectedNumCoords += 5; |
| 3288 | break; |
| 3289 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3290 | context->validationError(GL_INVALID_ENUM, kInvalidPathCommand); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3291 | return false; |
| 3292 | } |
| 3293 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3294 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3295 | if (expectedNumCoords != numCoords) |
| 3296 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3297 | context->validationError(GL_INVALID_VALUE, kInvalidPathNumCoords); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3298 | return false; |
| 3299 | } |
| 3300 | |
| 3301 | return true; |
| 3302 | } |
| 3303 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3304 | bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3305 | { |
| 3306 | if (!context->getExtensions().pathRendering) |
| 3307 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3308 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3309 | return false; |
| 3310 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3311 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3312 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3313 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3314 | return false; |
| 3315 | } |
| 3316 | |
| 3317 | switch (pname) |
| 3318 | { |
| 3319 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3320 | if (value < 0.0f) |
| 3321 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3322 | context->validationError(GL_INVALID_VALUE, kInvalidPathStrokeWidth); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3323 | return false; |
| 3324 | } |
| 3325 | break; |
| 3326 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3327 | switch (static_cast<GLenum>(value)) |
| 3328 | { |
| 3329 | case GL_FLAT_CHROMIUM: |
| 3330 | case GL_SQUARE_CHROMIUM: |
| 3331 | case GL_ROUND_CHROMIUM: |
| 3332 | break; |
| 3333 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3334 | context->validationError(GL_INVALID_ENUM, kInvalidPathEndCaps); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3335 | return false; |
| 3336 | } |
| 3337 | break; |
| 3338 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3339 | switch (static_cast<GLenum>(value)) |
| 3340 | { |
| 3341 | case GL_MITER_REVERT_CHROMIUM: |
| 3342 | case GL_BEVEL_CHROMIUM: |
| 3343 | case GL_ROUND_CHROMIUM: |
| 3344 | break; |
| 3345 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3346 | context->validationError(GL_INVALID_ENUM, kInvalidPathJoinStyle); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3347 | return false; |
| 3348 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3349 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3350 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3351 | if (value < 0.0f) |
| 3352 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3353 | context->validationError(GL_INVALID_VALUE, kInvalidPathMiterLimit); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3354 | return false; |
| 3355 | } |
| 3356 | break; |
| 3357 | |
| 3358 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3359 | // no errors, only clamping. |
| 3360 | break; |
| 3361 | |
| 3362 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3363 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3364 | return false; |
| 3365 | } |
| 3366 | return true; |
| 3367 | } |
| 3368 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3369 | bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value) |
| 3370 | { |
| 3371 | // TODO(jmadill): Use proper clamping cast. |
| 3372 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3373 | } |
| 3374 | |
| 3375 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3376 | { |
| 3377 | if (!context->getExtensions().pathRendering) |
| 3378 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3379 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3380 | return false; |
| 3381 | } |
| 3382 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3383 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3384 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3385 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3386 | return false; |
| 3387 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3388 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3389 | if (!value) |
| 3390 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3391 | context->validationError(GL_INVALID_VALUE, kInvalidPathValueArray); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3392 | return false; |
| 3393 | } |
| 3394 | |
| 3395 | switch (pname) |
| 3396 | { |
| 3397 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3398 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3399 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3400 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3401 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3402 | break; |
| 3403 | |
| 3404 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3405 | context->validationError(GL_INVALID_ENUM, kInvalidPathParameter); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3406 | return false; |
| 3407 | } |
| 3408 | |
| 3409 | return true; |
| 3410 | } |
| 3411 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3412 | bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value) |
| 3413 | { |
| 3414 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3415 | reinterpret_cast<GLfloat *>(value)); |
| 3416 | } |
| 3417 | |
| 3418 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3419 | { |
| 3420 | if (!context->getExtensions().pathRendering) |
| 3421 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3422 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3423 | return false; |
| 3424 | } |
| 3425 | |
| 3426 | switch (func) |
| 3427 | { |
| 3428 | case GL_NEVER: |
| 3429 | case GL_ALWAYS: |
| 3430 | case GL_LESS: |
| 3431 | case GL_LEQUAL: |
| 3432 | case GL_EQUAL: |
| 3433 | case GL_GEQUAL: |
| 3434 | case GL_GREATER: |
| 3435 | case GL_NOTEQUAL: |
| 3436 | break; |
| 3437 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3438 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3439 | return false; |
| 3440 | } |
| 3441 | |
| 3442 | return true; |
| 3443 | } |
| 3444 | |
| 3445 | // Note that the spec specifies that for the path drawing commands |
| 3446 | // if the path object is not an existing path object the command |
| 3447 | // does nothing and no error is generated. |
| 3448 | // However if the path object exists but has not been specified any |
| 3449 | // commands then an error is generated. |
| 3450 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3451 | bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3452 | { |
| 3453 | if (!context->getExtensions().pathRendering) |
| 3454 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3455 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3456 | return false; |
| 3457 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3458 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3459 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3460 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3461 | return false; |
| 3462 | } |
| 3463 | |
| 3464 | switch (fillMode) |
| 3465 | { |
| 3466 | case GL_COUNT_UP_CHROMIUM: |
| 3467 | case GL_COUNT_DOWN_CHROMIUM: |
| 3468 | break; |
| 3469 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3470 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3471 | return false; |
| 3472 | } |
| 3473 | |
| 3474 | if (!isPow2(mask + 1)) |
| 3475 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3476 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3477 | return false; |
| 3478 | } |
| 3479 | |
| 3480 | return true; |
| 3481 | } |
| 3482 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3483 | bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3484 | { |
| 3485 | if (!context->getExtensions().pathRendering) |
| 3486 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3487 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3488 | return false; |
| 3489 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3490 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3491 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3492 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3493 | context->validationError(GL_INVALID_OPERATION, kNoPathOrNoPathData); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3494 | return false; |
| 3495 | } |
| 3496 | |
| 3497 | return true; |
| 3498 | } |
| 3499 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3500 | bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3501 | { |
| 3502 | if (!context->getExtensions().pathRendering) |
| 3503 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3504 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3505 | return false; |
| 3506 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3507 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3508 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3509 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3510 | return false; |
| 3511 | } |
| 3512 | |
| 3513 | switch (coverMode) |
| 3514 | { |
| 3515 | case GL_CONVEX_HULL_CHROMIUM: |
| 3516 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3517 | break; |
| 3518 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3519 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3520 | return false; |
| 3521 | } |
| 3522 | return true; |
| 3523 | } |
| 3524 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 3525 | bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3526 | { |
| 3527 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3528 | } |
| 3529 | |
| 3530 | bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3531 | { |
| 3532 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3533 | } |
| 3534 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3535 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
| 3536 | GLuint path, |
| 3537 | GLenum fillMode, |
| 3538 | GLuint mask, |
| 3539 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3540 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3541 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 3542 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3543 | } |
| 3544 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3545 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
| 3546 | GLuint path, |
| 3547 | GLint reference, |
| 3548 | GLuint mask, |
| 3549 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3550 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3551 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 3552 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3553 | } |
| 3554 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3555 | bool ValidateIsPathCHROMIUM(Context *context, GLuint path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3556 | { |
| 3557 | if (!context->getExtensions().pathRendering) |
| 3558 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3559 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3560 | return false; |
| 3561 | } |
| 3562 | return true; |
| 3563 | } |
| 3564 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3565 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 3566 | GLsizei numPaths, |
| 3567 | GLenum pathNameType, |
| 3568 | const void *paths, |
| 3569 | GLuint pathBase, |
| 3570 | GLenum coverMode, |
| 3571 | GLenum transformType, |
| 3572 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3573 | { |
| 3574 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3575 | transformType, transformValues)) |
| 3576 | return false; |
| 3577 | |
| 3578 | switch (coverMode) |
| 3579 | { |
| 3580 | case GL_CONVEX_HULL_CHROMIUM: |
| 3581 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3582 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3583 | break; |
| 3584 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3585 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3586 | return false; |
| 3587 | } |
| 3588 | |
| 3589 | return true; |
| 3590 | } |
| 3591 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3592 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3593 | GLsizei numPaths, |
| 3594 | GLenum pathNameType, |
| 3595 | const void *paths, |
| 3596 | GLuint pathBase, |
| 3597 | GLenum coverMode, |
| 3598 | GLenum transformType, |
| 3599 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3600 | { |
| 3601 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3602 | transformType, transformValues)) |
| 3603 | return false; |
| 3604 | |
| 3605 | switch (coverMode) |
| 3606 | { |
| 3607 | case GL_CONVEX_HULL_CHROMIUM: |
| 3608 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3609 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3610 | break; |
| 3611 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3612 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3613 | return false; |
| 3614 | } |
| 3615 | |
| 3616 | return true; |
| 3617 | } |
| 3618 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3619 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 3620 | GLsizei numPaths, |
| 3621 | GLenum pathNameType, |
| 3622 | const void *paths, |
| 3623 | GLuint pathBase, |
| 3624 | GLenum fillMode, |
| 3625 | GLuint mask, |
| 3626 | GLenum transformType, |
| 3627 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3628 | { |
| 3629 | |
| 3630 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3631 | transformType, transformValues)) |
| 3632 | return false; |
| 3633 | |
| 3634 | switch (fillMode) |
| 3635 | { |
| 3636 | case GL_COUNT_UP_CHROMIUM: |
| 3637 | case GL_COUNT_DOWN_CHROMIUM: |
| 3638 | break; |
| 3639 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3640 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3641 | return false; |
| 3642 | } |
| 3643 | if (!isPow2(mask + 1)) |
| 3644 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3645 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3646 | return false; |
| 3647 | } |
| 3648 | return true; |
| 3649 | } |
| 3650 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3651 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 3652 | GLsizei numPaths, |
| 3653 | GLenum pathNameType, |
| 3654 | const void *paths, |
| 3655 | GLuint pathBase, |
| 3656 | GLint reference, |
| 3657 | GLuint mask, |
| 3658 | GLenum transformType, |
| 3659 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3660 | { |
| 3661 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3662 | transformType, transformValues)) |
| 3663 | return false; |
| 3664 | |
| 3665 | // no more validation here. |
| 3666 | |
| 3667 | return true; |
| 3668 | } |
| 3669 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3670 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 3671 | GLsizei numPaths, |
| 3672 | GLenum pathNameType, |
| 3673 | const void *paths, |
| 3674 | GLuint pathBase, |
| 3675 | GLenum fillMode, |
| 3676 | GLuint mask, |
| 3677 | GLenum coverMode, |
| 3678 | GLenum transformType, |
| 3679 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3680 | { |
| 3681 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3682 | transformType, transformValues)) |
| 3683 | return false; |
| 3684 | |
| 3685 | switch (coverMode) |
| 3686 | { |
| 3687 | case GL_CONVEX_HULL_CHROMIUM: |
| 3688 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3689 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3690 | break; |
| 3691 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3692 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3693 | return false; |
| 3694 | } |
| 3695 | |
| 3696 | switch (fillMode) |
| 3697 | { |
| 3698 | case GL_COUNT_UP_CHROMIUM: |
| 3699 | case GL_COUNT_DOWN_CHROMIUM: |
| 3700 | break; |
| 3701 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3702 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3703 | return false; |
| 3704 | } |
| 3705 | if (!isPow2(mask + 1)) |
| 3706 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3707 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3708 | return false; |
| 3709 | } |
| 3710 | |
| 3711 | return true; |
| 3712 | } |
| 3713 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3714 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3715 | GLsizei numPaths, |
| 3716 | GLenum pathNameType, |
| 3717 | const void *paths, |
| 3718 | GLuint pathBase, |
| 3719 | GLint reference, |
| 3720 | GLuint mask, |
| 3721 | GLenum coverMode, |
| 3722 | GLenum transformType, |
| 3723 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3724 | { |
| 3725 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3726 | transformType, transformValues)) |
| 3727 | return false; |
| 3728 | |
| 3729 | switch (coverMode) |
| 3730 | { |
| 3731 | case GL_CONVEX_HULL_CHROMIUM: |
| 3732 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3733 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3734 | break; |
| 3735 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3736 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3737 | return false; |
| 3738 | } |
| 3739 | |
| 3740 | return true; |
| 3741 | } |
| 3742 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3743 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
| 3744 | GLuint program, |
| 3745 | GLint location, |
| 3746 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3747 | { |
| 3748 | if (!context->getExtensions().pathRendering) |
| 3749 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3750 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3751 | return false; |
| 3752 | } |
| 3753 | |
| 3754 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 3755 | if (location >= MaxLocation) |
| 3756 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3757 | context->validationError(GL_INVALID_VALUE, kInvalidVaryingLocation); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3758 | return false; |
| 3759 | } |
| 3760 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3761 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3762 | if (!programObject) |
| 3763 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3764 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3765 | return false; |
| 3766 | } |
| 3767 | |
| 3768 | if (!name) |
| 3769 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3770 | context->validationError(GL_INVALID_VALUE, kMissingName); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3771 | return false; |
| 3772 | } |
| 3773 | |
| 3774 | if (angle::BeginsWith(name, "gl_")) |
| 3775 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3776 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +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 ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
| 3784 | GLuint program, |
| 3785 | GLint location, |
| 3786 | GLenum genMode, |
| 3787 | GLint components, |
| 3788 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3789 | { |
| 3790 | if (!context->getExtensions().pathRendering) |
| 3791 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3792 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3793 | return false; |
| 3794 | } |
| 3795 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3796 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3797 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 3798 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3799 | context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3800 | return false; |
| 3801 | } |
| 3802 | |
| 3803 | if (!programObject->isLinked()) |
| 3804 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3805 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3806 | return false; |
| 3807 | } |
| 3808 | |
| 3809 | switch (genMode) |
| 3810 | { |
| 3811 | case GL_NONE: |
| 3812 | if (components != 0) |
| 3813 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3814 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3815 | return false; |
| 3816 | } |
| 3817 | break; |
| 3818 | |
| 3819 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 3820 | case GL_EYE_LINEAR_CHROMIUM: |
| 3821 | case GL_CONSTANT_CHROMIUM: |
| 3822 | if (components < 1 || components > 4) |
| 3823 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3824 | context->validationError(GL_INVALID_VALUE, kInvalidComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3825 | return false; |
| 3826 | } |
| 3827 | if (!coeffs) |
| 3828 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3829 | context->validationError(GL_INVALID_VALUE, kInvalidPathCoefficientsArray); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3830 | return false; |
| 3831 | } |
| 3832 | break; |
| 3833 | |
| 3834 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3835 | context->validationError(GL_INVALID_ENUM, kInvalidPathGenMode); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3836 | return false; |
| 3837 | } |
| 3838 | |
| 3839 | // If the location is -1 then the command is silently ignored |
| 3840 | // and no further validation is needed. |
| 3841 | if (location == -1) |
| 3842 | return true; |
| 3843 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3844 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3845 | |
| 3846 | if (!binding.valid) |
| 3847 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3848 | context->validationError(GL_INVALID_OPERATION, kInvalidFragmentInputBinding); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3849 | return false; |
| 3850 | } |
| 3851 | |
| 3852 | if (binding.type != GL_NONE) |
| 3853 | { |
| 3854 | GLint expectedComponents = 0; |
| 3855 | switch (binding.type) |
| 3856 | { |
| 3857 | case GL_FLOAT: |
| 3858 | expectedComponents = 1; |
| 3859 | break; |
| 3860 | case GL_FLOAT_VEC2: |
| 3861 | expectedComponents = 2; |
| 3862 | break; |
| 3863 | case GL_FLOAT_VEC3: |
| 3864 | expectedComponents = 3; |
| 3865 | break; |
| 3866 | case GL_FLOAT_VEC4: |
| 3867 | expectedComponents = 4; |
| 3868 | break; |
| 3869 | default: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3870 | context->validationError(GL_INVALID_OPERATION, kFragmentInputTypeNotFloatingPoint); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3871 | return false; |
| 3872 | } |
| 3873 | if (expectedComponents != components && genMode != GL_NONE) |
| 3874 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3875 | context->validationError(GL_INVALID_OPERATION, kInvalidPathComponents); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3876 | return false; |
| 3877 | } |
| 3878 | } |
| 3879 | return true; |
| 3880 | } |
| 3881 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3882 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 3883 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3884 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3885 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3886 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3887 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3888 | GLint internalFormat, |
| 3889 | GLenum destType, |
| 3890 | GLboolean unpackFlipY, |
| 3891 | GLboolean unpackPremultiplyAlpha, |
| 3892 | GLboolean unpackUnmultiplyAlpha) |
| 3893 | { |
| 3894 | if (!context->getExtensions().copyTexture) |
| 3895 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3896 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3897 | return false; |
| 3898 | } |
| 3899 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3900 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3901 | if (source == nullptr) |
| 3902 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3903 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3904 | return false; |
| 3905 | } |
| 3906 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3907 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3908 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3909 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3910 | return false; |
| 3911 | } |
| 3912 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3913 | TextureType sourceType = source->getType(); |
| 3914 | ASSERT(sourceType != TextureType::CubeMap); |
| 3915 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3916 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3917 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3918 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3919 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3920 | return false; |
| 3921 | } |
| 3922 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3923 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 3924 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 3925 | if (sourceWidth == 0 || sourceHeight == 0) |
| 3926 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3927 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3928 | return false; |
| 3929 | } |
| 3930 | |
| 3931 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 3932 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3933 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3934 | context->validationError(GL_INVALID_OPERATION, kInvalidSourceTextureInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3935 | return false; |
| 3936 | } |
| 3937 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 3938 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 3939 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3940 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 3941 | return false; |
| 3942 | } |
| 3943 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3944 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3945 | if (dest == nullptr) |
| 3946 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3947 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3948 | return false; |
| 3949 | } |
| 3950 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3951 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3952 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3953 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3954 | return false; |
| 3955 | } |
| 3956 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3957 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 3958 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3959 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3960 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3961 | return false; |
| 3962 | } |
| 3963 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3964 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 3965 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3966 | return false; |
| 3967 | } |
| 3968 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3969 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3970 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3971 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 3972 | return false; |
| 3973 | } |
| 3974 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3975 | if (dest->getImmutableFormat()) |
| 3976 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3977 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3978 | return false; |
| 3979 | } |
| 3980 | |
| 3981 | return true; |
| 3982 | } |
| 3983 | |
| 3984 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 3985 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3986 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3987 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3988 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3989 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3990 | GLint xoffset, |
| 3991 | GLint yoffset, |
| 3992 | GLint x, |
| 3993 | GLint y, |
| 3994 | GLsizei width, |
| 3995 | GLsizei height, |
| 3996 | GLboolean unpackFlipY, |
| 3997 | GLboolean unpackPremultiplyAlpha, |
| 3998 | GLboolean unpackUnmultiplyAlpha) |
| 3999 | { |
| 4000 | if (!context->getExtensions().copyTexture) |
| 4001 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4002 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4003 | return false; |
| 4004 | } |
| 4005 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4006 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4007 | if (source == nullptr) |
| 4008 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4009 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4010 | return false; |
| 4011 | } |
| 4012 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4013 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4014 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4015 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4016 | return false; |
| 4017 | } |
| 4018 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4019 | TextureType sourceType = source->getType(); |
| 4020 | ASSERT(sourceType != TextureType::CubeMap); |
| 4021 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4022 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4023 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4024 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4025 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4026 | return false; |
| 4027 | } |
| 4028 | |
| 4029 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4030 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4031 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4032 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4033 | return false; |
| 4034 | } |
| 4035 | |
| 4036 | if (x < 0 || y < 0) |
| 4037 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4038 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4039 | return false; |
| 4040 | } |
| 4041 | |
| 4042 | if (width < 0 || height < 0) |
| 4043 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4044 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4045 | return false; |
| 4046 | } |
| 4047 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4048 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4049 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4050 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4051 | context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4052 | return false; |
| 4053 | } |
| 4054 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4055 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4056 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4057 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4058 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4059 | return false; |
| 4060 | } |
| 4061 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4062 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4063 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4064 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4065 | return false; |
| 4066 | } |
| 4067 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4068 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4069 | if (dest == nullptr) |
| 4070 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4071 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4072 | return false; |
| 4073 | } |
| 4074 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4075 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4076 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4077 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4078 | return false; |
| 4079 | } |
| 4080 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4081 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4082 | true)) |
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, kInvalidMipLevel); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4085 | return false; |
| 4086 | } |
| 4087 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4088 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4089 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4090 | context->validationError(GL_INVALID_OPERATION, kDestinationLevelNotDefined); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4091 | return false; |
| 4092 | } |
| 4093 | |
| 4094 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4095 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4096 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4097 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4098 | return false; |
| 4099 | } |
| 4100 | |
| 4101 | if (xoffset < 0 || yoffset < 0) |
| 4102 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4103 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4104 | return false; |
| 4105 | } |
| 4106 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4107 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4108 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4109 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4110 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4111 | return false; |
| 4112 | } |
| 4113 | |
| 4114 | return true; |
| 4115 | } |
| 4116 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4117 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 4118 | { |
| 4119 | if (!context->getExtensions().copyCompressedTexture) |
| 4120 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4121 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4122 | return false; |
| 4123 | } |
| 4124 | |
| 4125 | const gl::Texture *source = context->getTexture(sourceId); |
| 4126 | if (source == nullptr) |
| 4127 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4128 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4129 | return false; |
| 4130 | } |
| 4131 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4132 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4133 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4134 | context->validationError(GL_INVALID_VALUE, kInvalidSourceTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4135 | return false; |
| 4136 | } |
| 4137 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4138 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4139 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4140 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4141 | context->validationError(GL_INVALID_VALUE, kSourceTextureLevelZeroDefined); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4142 | return false; |
| 4143 | } |
| 4144 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4145 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4146 | if (!sourceFormat.info->compressed) |
| 4147 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4148 | context->validationError(GL_INVALID_OPERATION, kSourceTextureMustBeCompressed); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4149 | return false; |
| 4150 | } |
| 4151 | |
| 4152 | const gl::Texture *dest = context->getTexture(destId); |
| 4153 | if (dest == nullptr) |
| 4154 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4155 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTexture); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4156 | return false; |
| 4157 | } |
| 4158 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4159 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4160 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4161 | context->validationError(GL_INVALID_VALUE, kInvalidDestinationTextureType); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4162 | return false; |
| 4163 | } |
| 4164 | |
| 4165 | if (dest->getImmutableFormat()) |
| 4166 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4167 | context->validationError(GL_INVALID_OPERATION, kDestinationImmutable); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4168 | return false; |
| 4169 | } |
| 4170 | |
| 4171 | return true; |
| 4172 | } |
| 4173 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4174 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4175 | { |
| 4176 | switch (type) |
| 4177 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4178 | case ShaderType::Vertex: |
| 4179 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4180 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4181 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4182 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4183 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4184 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4185 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4186 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4187 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4188 | break; |
| 4189 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4190 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4191 | if (!context->getExtensions().geometryShader) |
| 4192 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4193 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4194 | return false; |
| 4195 | } |
| 4196 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4197 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4198 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4199 | return false; |
| 4200 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4201 | |
| 4202 | return true; |
| 4203 | } |
| 4204 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4205 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4206 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4207 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4208 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4209 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4210 | { |
| 4211 | if (size < 0) |
| 4212 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4213 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4214 | return false; |
| 4215 | } |
| 4216 | |
| 4217 | switch (usage) |
| 4218 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4219 | case BufferUsage::StreamDraw: |
| 4220 | case BufferUsage::StaticDraw: |
| 4221 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4222 | break; |
| 4223 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4224 | case BufferUsage::StreamRead: |
| 4225 | case BufferUsage::StaticRead: |
| 4226 | case BufferUsage::DynamicRead: |
| 4227 | case BufferUsage::StreamCopy: |
| 4228 | case BufferUsage::StaticCopy: |
| 4229 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4230 | if (context->getClientMajorVersion() < 3) |
| 4231 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4232 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4233 | return false; |
| 4234 | } |
| 4235 | break; |
| 4236 | |
| 4237 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4238 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4239 | return false; |
| 4240 | } |
| 4241 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4242 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4243 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4244 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4245 | return false; |
| 4246 | } |
| 4247 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4248 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4249 | |
| 4250 | if (!buffer) |
| 4251 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4252 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4253 | return false; |
| 4254 | } |
| 4255 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4256 | if (context->getExtensions().webglCompatibility && |
| 4257 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4258 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4259 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4260 | return false; |
| 4261 | } |
| 4262 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4263 | return true; |
| 4264 | } |
| 4265 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4266 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4267 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4268 | GLintptr offset, |
| 4269 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4270 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4271 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4272 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4273 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4274 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4275 | return false; |
| 4276 | } |
| 4277 | |
| 4278 | if (offset < 0) |
| 4279 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4280 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4281 | return false; |
| 4282 | } |
| 4283 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4284 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4285 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4286 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4287 | return false; |
| 4288 | } |
| 4289 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4290 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4291 | |
| 4292 | if (!buffer) |
| 4293 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4294 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4295 | return false; |
| 4296 | } |
| 4297 | |
| 4298 | if (buffer->isMapped()) |
| 4299 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4300 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4301 | return false; |
| 4302 | } |
| 4303 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4304 | if (context->getExtensions().webglCompatibility && |
| 4305 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4306 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4307 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4308 | return false; |
| 4309 | } |
| 4310 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4311 | // Check for possible overflow of size + offset |
| 4312 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4313 | checkedSize += offset; |
| 4314 | if (!checkedSize.IsValid()) |
| 4315 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4316 | context->validationError(GL_INVALID_VALUE, kParamOverflow); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4317 | return false; |
| 4318 | } |
| 4319 | |
| 4320 | if (size + offset > buffer->getSize()) |
| 4321 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4322 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4323 | return false; |
| 4324 | } |
| 4325 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4326 | return true; |
| 4327 | } |
| 4328 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4329 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4330 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4331 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4332 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4333 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4334 | return false; |
| 4335 | } |
| 4336 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4337 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4338 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4339 | context->validationError(GL_INVALID_OPERATION, kExtensionNotRequestable); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4340 | return false; |
| 4341 | } |
| 4342 | |
| 4343 | return true; |
| 4344 | } |
| 4345 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4346 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4347 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4348 | if (context->getClientMajorVersion() < 2) |
| 4349 | { |
| 4350 | return ValidateMultitextureUnit(context, texture); |
| 4351 | } |
| 4352 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4353 | if (texture < GL_TEXTURE0 || |
| 4354 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4355 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4356 | context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4357 | return false; |
| 4358 | } |
| 4359 | |
| 4360 | return true; |
| 4361 | } |
| 4362 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4363 | bool ValidateAttachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4364 | { |
| 4365 | Program *programObject = GetValidProgram(context, program); |
| 4366 | if (!programObject) |
| 4367 | { |
| 4368 | return false; |
| 4369 | } |
| 4370 | |
| 4371 | Shader *shaderObject = GetValidShader(context, shader); |
| 4372 | if (!shaderObject) |
| 4373 | { |
| 4374 | return false; |
| 4375 | } |
| 4376 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4377 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4378 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4379 | context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4380 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | return true; |
| 4384 | } |
| 4385 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4386 | bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4387 | { |
| 4388 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4389 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4390 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4391 | return false; |
| 4392 | } |
| 4393 | |
| 4394 | if (strncmp(name, "gl_", 3) == 0) |
| 4395 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4396 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4397 | return false; |
| 4398 | } |
| 4399 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4400 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4401 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4402 | const size_t length = strlen(name); |
| 4403 | |
| 4404 | if (!IsValidESSLString(name, length)) |
| 4405 | { |
| 4406 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4407 | // for shader-related entry points |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4408 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4409 | return false; |
| 4410 | } |
| 4411 | |
| 4412 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4413 | { |
| 4414 | return false; |
| 4415 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4416 | } |
| 4417 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4418 | return GetValidProgram(context, program) != nullptr; |
| 4419 | } |
| 4420 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4421 | bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4422 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4423 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4424 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4425 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4426 | return false; |
| 4427 | } |
| 4428 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4429 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4430 | !context->isFramebufferGenerated(framebuffer)) |
| 4431 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4432 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4433 | return false; |
| 4434 | } |
| 4435 | |
| 4436 | return true; |
| 4437 | } |
| 4438 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4439 | bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4440 | { |
| 4441 | if (target != GL_RENDERBUFFER) |
| 4442 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4443 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4444 | return false; |
| 4445 | } |
| 4446 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4447 | if (!context->getState().isBindGeneratesResourceEnabled() && |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4448 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4449 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4450 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4451 | return false; |
| 4452 | } |
| 4453 | |
| 4454 | return true; |
| 4455 | } |
| 4456 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4457 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4458 | { |
| 4459 | switch (mode) |
| 4460 | { |
| 4461 | case GL_FUNC_ADD: |
| 4462 | case GL_FUNC_SUBTRACT: |
| 4463 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4464 | return true; |
| 4465 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4466 | case GL_MIN: |
| 4467 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4468 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4469 | |
| 4470 | default: |
| 4471 | return false; |
| 4472 | } |
| 4473 | } |
| 4474 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4475 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4476 | { |
| 4477 | return true; |
| 4478 | } |
| 4479 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4480 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4481 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4482 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4483 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4484 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4485 | return false; |
| 4486 | } |
| 4487 | |
| 4488 | return true; |
| 4489 | } |
| 4490 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4491 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4492 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4493 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4494 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4495 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4496 | return false; |
| 4497 | } |
| 4498 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4499 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4500 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4501 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -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 ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4509 | { |
| 4510 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 4511 | } |
| 4512 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4513 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4514 | GLenum srcRGB, |
| 4515 | GLenum dstRGB, |
| 4516 | GLenum srcAlpha, |
| 4517 | GLenum dstAlpha) |
| 4518 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4519 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4520 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4521 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4522 | return false; |
| 4523 | } |
| 4524 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4525 | if (!ValidDstBlendFunc(context, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4526 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4527 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4528 | return false; |
| 4529 | } |
| 4530 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4531 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4532 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4533 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4534 | return false; |
| 4535 | } |
| 4536 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4537 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4538 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4539 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4540 | return false; |
| 4541 | } |
| 4542 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4543 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 4544 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4545 | { |
| 4546 | bool constantColorUsed = |
| 4547 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 4548 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 4549 | |
| 4550 | bool constantAlphaUsed = |
| 4551 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 4552 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 4553 | |
| 4554 | if (constantColorUsed && constantAlphaUsed) |
| 4555 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4556 | if (context->getExtensions().webglCompatibility) |
| 4557 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4558 | context->validationError(GL_INVALID_OPERATION, kInvalidConstantColor); |
| 4559 | return false; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4560 | } |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4561 | |
| 4562 | WARN() << kConstantColorAlphaLimitation; |
| 4563 | context->validationError(GL_INVALID_OPERATION, kConstantColorAlphaLimitation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4564 | return false; |
| 4565 | } |
| 4566 | } |
| 4567 | |
| 4568 | return true; |
| 4569 | } |
| 4570 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4571 | bool ValidateGetString(Context *context, GLenum name) |
| 4572 | { |
| 4573 | switch (name) |
| 4574 | { |
| 4575 | case GL_VENDOR: |
| 4576 | case GL_RENDERER: |
| 4577 | case GL_VERSION: |
| 4578 | case GL_SHADING_LANGUAGE_VERSION: |
| 4579 | case GL_EXTENSIONS: |
| 4580 | break; |
| 4581 | |
| 4582 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 4583 | if (!context->getExtensions().requestExtension) |
| 4584 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4585 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4586 | return false; |
| 4587 | } |
| 4588 | break; |
| 4589 | |
| 4590 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4591 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4592 | return false; |
| 4593 | } |
| 4594 | |
| 4595 | return true; |
| 4596 | } |
| 4597 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4598 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4599 | { |
| 4600 | if (width <= 0.0f || isNaN(width)) |
| 4601 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4602 | context->validationError(GL_INVALID_VALUE, kInvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4603 | return false; |
| 4604 | } |
| 4605 | |
| 4606 | return true; |
| 4607 | } |
| 4608 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4609 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4610 | { |
| 4611 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 4612 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4613 | context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4614 | return false; |
| 4615 | } |
| 4616 | |
| 4617 | return true; |
| 4618 | } |
| 4619 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4620 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4621 | GLenum target, |
| 4622 | GLenum internalformat, |
| 4623 | GLsizei width, |
| 4624 | GLsizei height) |
| 4625 | { |
| 4626 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 4627 | height); |
| 4628 | } |
| 4629 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4630 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4631 | GLenum target, |
| 4632 | GLsizei samples, |
| 4633 | GLenum internalformat, |
| 4634 | GLsizei width, |
| 4635 | GLsizei height) |
| 4636 | { |
| 4637 | if (!context->getExtensions().framebufferMultisample) |
| 4638 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4639 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4640 | return false; |
| 4641 | } |
| 4642 | |
| 4643 | // 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] | 4644 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4645 | // generated. |
| 4646 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 4647 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4648 | context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4649 | return false; |
| 4650 | } |
| 4651 | |
| 4652 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 4653 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 4654 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 4655 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 4656 | if (context->getClientMajorVersion() >= 3) |
| 4657 | { |
| 4658 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 4659 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 4660 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4661 | context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4662 | return false; |
| 4663 | } |
| 4664 | } |
| 4665 | |
| 4666 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 4667 | width, height); |
| 4668 | } |
| 4669 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4670 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4671 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4672 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4673 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4674 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4675 | return false; |
| 4676 | } |
| 4677 | |
| 4678 | return true; |
| 4679 | } |
| 4680 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4681 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4682 | { |
| 4683 | return true; |
| 4684 | } |
| 4685 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4686 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4687 | { |
| 4688 | return true; |
| 4689 | } |
| 4690 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4691 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4692 | { |
| 4693 | return true; |
| 4694 | } |
| 4695 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4696 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4697 | GLboolean red, |
| 4698 | GLboolean green, |
| 4699 | GLboolean blue, |
| 4700 | GLboolean alpha) |
| 4701 | { |
| 4702 | return true; |
| 4703 | } |
| 4704 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4705 | bool ValidateCompileShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4706 | { |
| 4707 | return true; |
| 4708 | } |
| 4709 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4710 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4711 | { |
| 4712 | return true; |
| 4713 | } |
| 4714 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4715 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4716 | { |
| 4717 | switch (mode) |
| 4718 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4719 | case CullFaceMode::Front: |
| 4720 | case CullFaceMode::Back: |
| 4721 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4722 | break; |
| 4723 | |
| 4724 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4725 | context->validationError(GL_INVALID_ENUM, kInvalidCullMode); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4726 | return false; |
| 4727 | } |
| 4728 | |
| 4729 | return true; |
| 4730 | } |
| 4731 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4732 | bool ValidateDeleteProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4733 | { |
| 4734 | if (program == 0) |
| 4735 | { |
| 4736 | return false; |
| 4737 | } |
| 4738 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4739 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4740 | { |
| 4741 | if (context->getShader(program)) |
| 4742 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4743 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4744 | return false; |
| 4745 | } |
| 4746 | else |
| 4747 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4748 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4749 | return false; |
| 4750 | } |
| 4751 | } |
| 4752 | |
| 4753 | return true; |
| 4754 | } |
| 4755 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4756 | bool ValidateDeleteShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4757 | { |
| 4758 | if (shader == 0) |
| 4759 | { |
| 4760 | return false; |
| 4761 | } |
| 4762 | |
| 4763 | if (!context->getShader(shader)) |
| 4764 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4765 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4766 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4767 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4768 | return false; |
| 4769 | } |
| 4770 | else |
| 4771 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4772 | context->validationError(GL_INVALID_VALUE, kExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4773 | return false; |
| 4774 | } |
| 4775 | } |
| 4776 | |
| 4777 | return true; |
| 4778 | } |
| 4779 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4780 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4781 | { |
| 4782 | switch (func) |
| 4783 | { |
| 4784 | case GL_NEVER: |
| 4785 | case GL_ALWAYS: |
| 4786 | case GL_LESS: |
| 4787 | case GL_LEQUAL: |
| 4788 | case GL_EQUAL: |
| 4789 | case GL_GREATER: |
| 4790 | case GL_GEQUAL: |
| 4791 | case GL_NOTEQUAL: |
| 4792 | break; |
| 4793 | |
| 4794 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4795 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4796 | return false; |
| 4797 | } |
| 4798 | |
| 4799 | return true; |
| 4800 | } |
| 4801 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4802 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4803 | { |
| 4804 | return true; |
| 4805 | } |
| 4806 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4807 | bool ValidateDetachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4808 | { |
| 4809 | Program *programObject = GetValidProgram(context, program); |
| 4810 | if (!programObject) |
| 4811 | { |
| 4812 | return false; |
| 4813 | } |
| 4814 | |
| 4815 | Shader *shaderObject = GetValidShader(context, shader); |
| 4816 | if (!shaderObject) |
| 4817 | { |
| 4818 | return false; |
| 4819 | } |
| 4820 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4821 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4822 | if (attachedShader != shaderObject) |
| 4823 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4824 | context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4825 | return false; |
| 4826 | } |
| 4827 | |
| 4828 | return true; |
| 4829 | } |
| 4830 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4831 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4832 | { |
| 4833 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4834 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4835 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4836 | return false; |
| 4837 | } |
| 4838 | |
| 4839 | return true; |
| 4840 | } |
| 4841 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4842 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4843 | { |
| 4844 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4845 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4846 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4847 | return false; |
| 4848 | } |
| 4849 | |
| 4850 | return true; |
| 4851 | } |
| 4852 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4853 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4854 | { |
| 4855 | return true; |
| 4856 | } |
| 4857 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4858 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4859 | { |
| 4860 | return true; |
| 4861 | } |
| 4862 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4863 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4864 | { |
| 4865 | switch (mode) |
| 4866 | { |
| 4867 | case GL_CW: |
| 4868 | case GL_CCW: |
| 4869 | break; |
| 4870 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4871 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4872 | return false; |
| 4873 | } |
| 4874 | |
| 4875 | return true; |
| 4876 | } |
| 4877 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4878 | bool ValidateGetActiveAttrib(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4879 | GLuint program, |
| 4880 | GLuint index, |
| 4881 | GLsizei bufsize, |
| 4882 | GLsizei *length, |
| 4883 | GLint *size, |
| 4884 | GLenum *type, |
| 4885 | GLchar *name) |
| 4886 | { |
| 4887 | if (bufsize < 0) |
| 4888 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4889 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4890 | return false; |
| 4891 | } |
| 4892 | |
| 4893 | Program *programObject = GetValidProgram(context, program); |
| 4894 | |
| 4895 | if (!programObject) |
| 4896 | { |
| 4897 | return false; |
| 4898 | } |
| 4899 | |
| 4900 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 4901 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4902 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4903 | return false; |
| 4904 | } |
| 4905 | |
| 4906 | return true; |
| 4907 | } |
| 4908 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4909 | bool ValidateGetActiveUniform(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4910 | GLuint program, |
| 4911 | GLuint index, |
| 4912 | GLsizei bufsize, |
| 4913 | GLsizei *length, |
| 4914 | GLint *size, |
| 4915 | GLenum *type, |
| 4916 | GLchar *name) |
| 4917 | { |
| 4918 | if (bufsize < 0) |
| 4919 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4920 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4921 | return false; |
| 4922 | } |
| 4923 | |
| 4924 | Program *programObject = GetValidProgram(context, program); |
| 4925 | |
| 4926 | if (!programObject) |
| 4927 | { |
| 4928 | return false; |
| 4929 | } |
| 4930 | |
| 4931 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 4932 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4933 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4934 | return false; |
| 4935 | } |
| 4936 | |
| 4937 | return true; |
| 4938 | } |
| 4939 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4940 | bool ValidateGetAttachedShaders(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4941 | GLuint program, |
| 4942 | GLsizei maxcount, |
| 4943 | GLsizei *count, |
| 4944 | GLuint *shaders) |
| 4945 | { |
| 4946 | if (maxcount < 0) |
| 4947 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4948 | context->validationError(GL_INVALID_VALUE, kNegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4949 | return false; |
| 4950 | } |
| 4951 | |
| 4952 | Program *programObject = GetValidProgram(context, program); |
| 4953 | |
| 4954 | if (!programObject) |
| 4955 | { |
| 4956 | return false; |
| 4957 | } |
| 4958 | |
| 4959 | return true; |
| 4960 | } |
| 4961 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4962 | bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4963 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4964 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 4965 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 4966 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4967 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4968 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4969 | return false; |
| 4970 | } |
| 4971 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4972 | Program *programObject = GetValidProgram(context, program); |
| 4973 | |
| 4974 | if (!programObject) |
| 4975 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4976 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4977 | return false; |
| 4978 | } |
| 4979 | |
| 4980 | if (!programObject->isLinked()) |
| 4981 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4982 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
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 ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4990 | { |
| 4991 | GLenum nativeType; |
| 4992 | unsigned int numParams = 0; |
| 4993 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 4994 | } |
| 4995 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4996 | bool ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4997 | { |
| 4998 | return true; |
| 4999 | } |
| 5000 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5001 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5002 | { |
| 5003 | GLenum nativeType; |
| 5004 | unsigned int numParams = 0; |
| 5005 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5006 | } |
| 5007 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5008 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5009 | { |
| 5010 | GLenum nativeType; |
| 5011 | unsigned int numParams = 0; |
| 5012 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5013 | } |
| 5014 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5015 | bool ValidateGetProgramInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5016 | GLuint program, |
| 5017 | GLsizei bufsize, |
| 5018 | GLsizei *length, |
| 5019 | GLchar *infolog) |
| 5020 | { |
| 5021 | if (bufsize < 0) |
| 5022 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5023 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5024 | return false; |
| 5025 | } |
| 5026 | |
| 5027 | Program *programObject = GetValidProgram(context, program); |
| 5028 | if (!programObject) |
| 5029 | { |
| 5030 | return false; |
| 5031 | } |
| 5032 | |
| 5033 | return true; |
| 5034 | } |
| 5035 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5036 | bool ValidateGetShaderInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5037 | GLuint shader, |
| 5038 | GLsizei bufsize, |
| 5039 | GLsizei *length, |
| 5040 | GLchar *infolog) |
| 5041 | { |
| 5042 | if (bufsize < 0) |
| 5043 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5044 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5045 | return false; |
| 5046 | } |
| 5047 | |
| 5048 | Shader *shaderObject = GetValidShader(context, shader); |
| 5049 | if (!shaderObject) |
| 5050 | { |
| 5051 | return false; |
| 5052 | } |
| 5053 | |
| 5054 | return true; |
| 5055 | } |
| 5056 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5057 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5058 | GLenum shadertype, |
| 5059 | GLenum precisiontype, |
| 5060 | GLint *range, |
| 5061 | GLint *precision) |
| 5062 | { |
| 5063 | switch (shadertype) |
| 5064 | { |
| 5065 | case GL_VERTEX_SHADER: |
| 5066 | case GL_FRAGMENT_SHADER: |
| 5067 | break; |
| 5068 | case GL_COMPUTE_SHADER: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5069 | context->validationError(GL_INVALID_OPERATION, kUnimplementedComputeShaderPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5070 | return false; |
| 5071 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5072 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5073 | return false; |
| 5074 | } |
| 5075 | |
| 5076 | switch (precisiontype) |
| 5077 | { |
| 5078 | case GL_LOW_FLOAT: |
| 5079 | case GL_MEDIUM_FLOAT: |
| 5080 | case GL_HIGH_FLOAT: |
| 5081 | case GL_LOW_INT: |
| 5082 | case GL_MEDIUM_INT: |
| 5083 | case GL_HIGH_INT: |
| 5084 | break; |
| 5085 | |
| 5086 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5087 | context->validationError(GL_INVALID_ENUM, kInvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5088 | return false; |
| 5089 | } |
| 5090 | |
| 5091 | return true; |
| 5092 | } |
| 5093 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5094 | bool ValidateGetShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5095 | GLuint shader, |
| 5096 | GLsizei bufsize, |
| 5097 | GLsizei *length, |
| 5098 | GLchar *source) |
| 5099 | { |
| 5100 | if (bufsize < 0) |
| 5101 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5102 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5103 | return false; |
| 5104 | } |
| 5105 | |
| 5106 | Shader *shaderObject = GetValidShader(context, shader); |
| 5107 | if (!shaderObject) |
| 5108 | { |
| 5109 | return false; |
| 5110 | } |
| 5111 | |
| 5112 | return true; |
| 5113 | } |
| 5114 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5115 | bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5116 | { |
| 5117 | if (strstr(name, "gl_") == name) |
| 5118 | { |
| 5119 | return false; |
| 5120 | } |
| 5121 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5122 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5123 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5124 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5125 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5126 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5127 | return false; |
| 5128 | } |
| 5129 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5130 | Program *programObject = GetValidProgram(context, program); |
| 5131 | |
| 5132 | if (!programObject) |
| 5133 | { |
| 5134 | return false; |
| 5135 | } |
| 5136 | |
| 5137 | if (!programObject->isLinked()) |
| 5138 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5139 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5140 | return false; |
| 5141 | } |
| 5142 | |
| 5143 | return true; |
| 5144 | } |
| 5145 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5146 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5147 | { |
| 5148 | switch (mode) |
| 5149 | { |
| 5150 | case GL_FASTEST: |
| 5151 | case GL_NICEST: |
| 5152 | case GL_DONT_CARE: |
| 5153 | break; |
| 5154 | |
| 5155 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5156 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5157 | return false; |
| 5158 | } |
| 5159 | |
| 5160 | switch (target) |
| 5161 | { |
| 5162 | case GL_GENERATE_MIPMAP_HINT: |
| 5163 | break; |
| 5164 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5165 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5166 | if (context->getClientVersion() < ES_3_0 && |
| 5167 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5168 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5169 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5170 | return false; |
| 5171 | } |
| 5172 | break; |
| 5173 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5174 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5175 | case GL_POINT_SMOOTH_HINT: |
| 5176 | case GL_LINE_SMOOTH_HINT: |
| 5177 | case GL_FOG_HINT: |
| 5178 | if (context->getClientMajorVersion() >= 2) |
| 5179 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5180 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5181 | return false; |
| 5182 | } |
| 5183 | break; |
| 5184 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5185 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5186 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5187 | return false; |
| 5188 | } |
| 5189 | |
| 5190 | return true; |
| 5191 | } |
| 5192 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5193 | bool ValidateIsBuffer(Context *context, GLuint buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5194 | { |
| 5195 | return true; |
| 5196 | } |
| 5197 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5198 | bool ValidateIsFramebuffer(Context *context, GLuint framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5199 | { |
| 5200 | return true; |
| 5201 | } |
| 5202 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5203 | bool ValidateIsProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5204 | { |
| 5205 | return true; |
| 5206 | } |
| 5207 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5208 | bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5209 | { |
| 5210 | return true; |
| 5211 | } |
| 5212 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5213 | bool ValidateIsShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5214 | { |
| 5215 | return true; |
| 5216 | } |
| 5217 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5218 | bool ValidateIsTexture(Context *context, GLuint texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5219 | { |
| 5220 | return true; |
| 5221 | } |
| 5222 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5223 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5224 | { |
| 5225 | if (context->getClientMajorVersion() < 3) |
| 5226 | { |
| 5227 | switch (pname) |
| 5228 | { |
| 5229 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5230 | case GL_UNPACK_SKIP_IMAGES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5231 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5232 | return false; |
| 5233 | |
| 5234 | case GL_UNPACK_ROW_LENGTH: |
| 5235 | case GL_UNPACK_SKIP_ROWS: |
| 5236 | case GL_UNPACK_SKIP_PIXELS: |
| 5237 | if (!context->getExtensions().unpackSubimage) |
| 5238 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5239 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5240 | return false; |
| 5241 | } |
| 5242 | break; |
| 5243 | |
| 5244 | case GL_PACK_ROW_LENGTH: |
| 5245 | case GL_PACK_SKIP_ROWS: |
| 5246 | case GL_PACK_SKIP_PIXELS: |
| 5247 | if (!context->getExtensions().packSubimage) |
| 5248 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5249 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5250 | return false; |
| 5251 | } |
| 5252 | break; |
| 5253 | } |
| 5254 | } |
| 5255 | |
| 5256 | if (param < 0) |
| 5257 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5258 | context->validationError(GL_INVALID_VALUE, kNegativeParam); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5259 | return false; |
| 5260 | } |
| 5261 | |
| 5262 | switch (pname) |
| 5263 | { |
| 5264 | case GL_UNPACK_ALIGNMENT: |
| 5265 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5266 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5267 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5268 | return false; |
| 5269 | } |
| 5270 | break; |
| 5271 | |
| 5272 | case GL_PACK_ALIGNMENT: |
| 5273 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5274 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5275 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5276 | return false; |
| 5277 | } |
| 5278 | break; |
| 5279 | |
| 5280 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5281 | if (!context->getExtensions().packReverseRowOrder) |
| 5282 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5283 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5284 | } |
| 5285 | break; |
| 5286 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5287 | case GL_UNPACK_ROW_LENGTH: |
| 5288 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5289 | case GL_UNPACK_SKIP_IMAGES: |
| 5290 | case GL_UNPACK_SKIP_ROWS: |
| 5291 | case GL_UNPACK_SKIP_PIXELS: |
| 5292 | case GL_PACK_ROW_LENGTH: |
| 5293 | case GL_PACK_SKIP_ROWS: |
| 5294 | case GL_PACK_SKIP_PIXELS: |
| 5295 | break; |
| 5296 | |
| 5297 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5298 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5299 | return false; |
| 5300 | } |
| 5301 | |
| 5302 | return true; |
| 5303 | } |
| 5304 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5305 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5306 | { |
| 5307 | return true; |
| 5308 | } |
| 5309 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5310 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5311 | { |
| 5312 | return true; |
| 5313 | } |
| 5314 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5315 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5316 | { |
| 5317 | return true; |
| 5318 | } |
| 5319 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5320 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5321 | { |
| 5322 | if (width < 0 || height < 0) |
| 5323 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5324 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5325 | return false; |
| 5326 | } |
| 5327 | |
| 5328 | return true; |
| 5329 | } |
| 5330 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5331 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5332 | GLsizei n, |
| 5333 | const GLuint *shaders, |
| 5334 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5335 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5336 | GLsizei length) |
| 5337 | { |
| 5338 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5339 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5340 | shaderBinaryFormats.end()) |
| 5341 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5342 | context->validationError(GL_INVALID_ENUM, kInvalidShaderBinaryFormat); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5343 | return false; |
| 5344 | } |
| 5345 | |
| 5346 | return true; |
| 5347 | } |
| 5348 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5349 | bool ValidateShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5350 | GLuint shader, |
| 5351 | GLsizei count, |
| 5352 | const GLchar *const *string, |
| 5353 | const GLint *length) |
| 5354 | { |
| 5355 | if (count < 0) |
| 5356 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5357 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5358 | return false; |
| 5359 | } |
| 5360 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5361 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5362 | // shader-related entry points |
| 5363 | if (context->getExtensions().webglCompatibility) |
| 5364 | { |
| 5365 | for (GLsizei i = 0; i < count; i++) |
| 5366 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5367 | size_t len = |
| 5368 | (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] | 5369 | |
| 5370 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5371 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5372 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5373 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5374 | context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5375 | return false; |
| 5376 | } |
| 5377 | } |
| 5378 | } |
| 5379 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5380 | Shader *shaderObject = GetValidShader(context, shader); |
| 5381 | if (!shaderObject) |
| 5382 | { |
| 5383 | return false; |
| 5384 | } |
| 5385 | |
| 5386 | return true; |
| 5387 | } |
| 5388 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5389 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5390 | { |
| 5391 | if (!IsValidStencilFunc(func)) |
| 5392 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5393 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5394 | return false; |
| 5395 | } |
| 5396 | |
| 5397 | return true; |
| 5398 | } |
| 5399 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5400 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5401 | { |
| 5402 | if (!IsValidStencilFace(face)) |
| 5403 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5404 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5405 | return false; |
| 5406 | } |
| 5407 | |
| 5408 | if (!IsValidStencilFunc(func)) |
| 5409 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5410 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5411 | return false; |
| 5412 | } |
| 5413 | |
| 5414 | return true; |
| 5415 | } |
| 5416 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5417 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5418 | { |
| 5419 | return true; |
| 5420 | } |
| 5421 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5422 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5423 | { |
| 5424 | if (!IsValidStencilFace(face)) |
| 5425 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5426 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5427 | return false; |
| 5428 | } |
| 5429 | |
| 5430 | return true; |
| 5431 | } |
| 5432 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5433 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5434 | { |
| 5435 | if (!IsValidStencilOp(fail)) |
| 5436 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5437 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5438 | return false; |
| 5439 | } |
| 5440 | |
| 5441 | if (!IsValidStencilOp(zfail)) |
| 5442 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5443 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5444 | return false; |
| 5445 | } |
| 5446 | |
| 5447 | if (!IsValidStencilOp(zpass)) |
| 5448 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5449 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5450 | return false; |
| 5451 | } |
| 5452 | |
| 5453 | return true; |
| 5454 | } |
| 5455 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5456 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5457 | GLenum face, |
| 5458 | GLenum fail, |
| 5459 | GLenum zfail, |
| 5460 | GLenum zpass) |
| 5461 | { |
| 5462 | if (!IsValidStencilFace(face)) |
| 5463 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5464 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5465 | return false; |
| 5466 | } |
| 5467 | |
| 5468 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5469 | } |
| 5470 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5471 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5472 | { |
| 5473 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5474 | } |
| 5475 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5476 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5477 | { |
| 5478 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5479 | } |
| 5480 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5481 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5482 | { |
| 5483 | return ValidateUniform1iv(context, location, 1, &x); |
| 5484 | } |
| 5485 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5486 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5487 | { |
| 5488 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 5489 | } |
| 5490 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5491 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5492 | { |
| 5493 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 5494 | } |
| 5495 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5496 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5497 | { |
| 5498 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 5499 | } |
| 5500 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5501 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5502 | { |
| 5503 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 5504 | } |
| 5505 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5506 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5507 | { |
| 5508 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 5509 | } |
| 5510 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5511 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5512 | { |
| 5513 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 5514 | } |
| 5515 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5516 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5517 | { |
| 5518 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 5519 | } |
| 5520 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5521 | 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] | 5522 | { |
| 5523 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 5524 | } |
| 5525 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5526 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5527 | { |
| 5528 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 5529 | } |
| 5530 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5531 | 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] | 5532 | { |
| 5533 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 5534 | } |
| 5535 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5536 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5537 | { |
| 5538 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 5539 | } |
| 5540 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5541 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5542 | GLint location, |
| 5543 | GLsizei count, |
| 5544 | GLboolean transpose, |
| 5545 | const GLfloat *value) |
| 5546 | { |
| 5547 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 5548 | } |
| 5549 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5550 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5551 | GLint location, |
| 5552 | GLsizei count, |
| 5553 | GLboolean transpose, |
| 5554 | const GLfloat *value) |
| 5555 | { |
| 5556 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 5557 | } |
| 5558 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5559 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5560 | GLint location, |
| 5561 | GLsizei count, |
| 5562 | GLboolean transpose, |
| 5563 | const GLfloat *value) |
| 5564 | { |
| 5565 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 5566 | } |
| 5567 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5568 | bool ValidateValidateProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5569 | { |
| 5570 | Program *programObject = GetValidProgram(context, program); |
| 5571 | |
| 5572 | if (!programObject) |
| 5573 | { |
| 5574 | return false; |
| 5575 | } |
| 5576 | |
| 5577 | return true; |
| 5578 | } |
| 5579 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5580 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5581 | { |
| 5582 | return ValidateVertexAttribIndex(context, index); |
| 5583 | } |
| 5584 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5585 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5586 | { |
| 5587 | return ValidateVertexAttribIndex(context, index); |
| 5588 | } |
| 5589 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5590 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5591 | { |
| 5592 | return ValidateVertexAttribIndex(context, index); |
| 5593 | } |
| 5594 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5595 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5596 | { |
| 5597 | return ValidateVertexAttribIndex(context, index); |
| 5598 | } |
| 5599 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5600 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5601 | { |
| 5602 | return ValidateVertexAttribIndex(context, index); |
| 5603 | } |
| 5604 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5605 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5606 | { |
| 5607 | return ValidateVertexAttribIndex(context, index); |
| 5608 | } |
| 5609 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5610 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5611 | GLuint index, |
| 5612 | GLfloat x, |
| 5613 | GLfloat y, |
| 5614 | GLfloat z, |
| 5615 | GLfloat w) |
| 5616 | { |
| 5617 | return ValidateVertexAttribIndex(context, index); |
| 5618 | } |
| 5619 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5620 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5621 | { |
| 5622 | return ValidateVertexAttribIndex(context, index); |
| 5623 | } |
| 5624 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5625 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5626 | { |
| 5627 | if (width < 0 || height < 0) |
| 5628 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5629 | context->validationError(GL_INVALID_VALUE, kViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5630 | return false; |
| 5631 | } |
| 5632 | |
| 5633 | return true; |
| 5634 | } |
| 5635 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 5636 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5637 | GLenum target, |
| 5638 | GLenum attachment, |
| 5639 | GLenum pname, |
| 5640 | GLint *params) |
| 5641 | { |
| 5642 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 5643 | nullptr); |
| 5644 | } |
| 5645 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5646 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5647 | { |
| 5648 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 5649 | } |
| 5650 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5651 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5652 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5653 | GLint level, |
| 5654 | GLenum internalformat, |
| 5655 | GLint x, |
| 5656 | GLint y, |
| 5657 | GLsizei width, |
| 5658 | GLsizei height, |
| 5659 | GLint border) |
| 5660 | { |
| 5661 | if (context->getClientMajorVersion() < 3) |
| 5662 | { |
| 5663 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 5664 | 0, x, y, width, height, border); |
| 5665 | } |
| 5666 | |
| 5667 | ASSERT(context->getClientMajorVersion() == 3); |
| 5668 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 5669 | 0, x, y, width, height, border); |
| 5670 | } |
| 5671 | |
| 5672 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5673 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5674 | GLint level, |
| 5675 | GLint xoffset, |
| 5676 | GLint yoffset, |
| 5677 | GLint x, |
| 5678 | GLint y, |
| 5679 | GLsizei width, |
| 5680 | GLsizei height) |
| 5681 | { |
| 5682 | if (context->getClientMajorVersion() < 3) |
| 5683 | { |
| 5684 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 5685 | yoffset, x, y, width, height, 0); |
| 5686 | } |
| 5687 | |
| 5688 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 5689 | yoffset, 0, x, y, width, height, 0); |
| 5690 | } |
| 5691 | |
| 5692 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 5693 | { |
| 5694 | return ValidateGenOrDelete(context, n); |
| 5695 | } |
| 5696 | |
| 5697 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 5698 | { |
| 5699 | return ValidateGenOrDelete(context, n); |
| 5700 | } |
| 5701 | |
| 5702 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 5703 | { |
| 5704 | return ValidateGenOrDelete(context, n); |
| 5705 | } |
| 5706 | |
| 5707 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 5708 | { |
| 5709 | return ValidateGenOrDelete(context, n); |
| 5710 | } |
| 5711 | |
| 5712 | bool ValidateDisable(Context *context, GLenum cap) |
| 5713 | { |
| 5714 | if (!ValidCap(context, cap, false)) |
| 5715 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5716 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5717 | return false; |
| 5718 | } |
| 5719 | |
| 5720 | return true; |
| 5721 | } |
| 5722 | |
| 5723 | bool ValidateEnable(Context *context, GLenum cap) |
| 5724 | { |
| 5725 | if (!ValidCap(context, cap, false)) |
| 5726 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5727 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5728 | return false; |
| 5729 | } |
| 5730 | |
| 5731 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 5732 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 5733 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5734 | context->validationError(GL_INVALID_OPERATION, kNoSampleAlphaToCoveragesLimitation); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5735 | |
| 5736 | // We also output an error message to the debugger window if tracing is active, so that |
| 5737 | // developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5738 | ERR() << kNoSampleAlphaToCoveragesLimitation; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5739 | return false; |
| 5740 | } |
| 5741 | |
| 5742 | return true; |
| 5743 | } |
| 5744 | |
| 5745 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 5746 | GLenum target, |
| 5747 | GLenum attachment, |
| 5748 | GLenum renderbuffertarget, |
| 5749 | GLuint renderbuffer) |
| 5750 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5751 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5752 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5753 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5754 | return false; |
| 5755 | } |
| 5756 | |
| 5757 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0) |
| 5758 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5759 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5760 | return false; |
| 5761 | } |
| 5762 | |
| 5763 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 5764 | renderbuffertarget, renderbuffer); |
| 5765 | } |
| 5766 | |
| 5767 | bool ValidateFramebufferTexture2D(Context *context, |
| 5768 | GLenum target, |
| 5769 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5770 | TextureTarget textarget, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5771 | GLuint texture, |
| 5772 | GLint level) |
| 5773 | { |
| 5774 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 5775 | // extension |
| 5776 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 5777 | level != 0) |
| 5778 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5779 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5780 | return false; |
| 5781 | } |
| 5782 | |
| 5783 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 5784 | { |
| 5785 | return false; |
| 5786 | } |
| 5787 | |
| 5788 | if (texture != 0) |
| 5789 | { |
| 5790 | gl::Texture *tex = context->getTexture(texture); |
| 5791 | ASSERT(tex); |
| 5792 | |
| 5793 | const gl::Caps &caps = context->getCaps(); |
| 5794 | |
| 5795 | switch (textarget) |
| 5796 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5797 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5798 | { |
| 5799 | if (level > gl::log2(caps.max2DTextureSize)) |
| 5800 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5801 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5802 | return false; |
| 5803 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 5804 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5805 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5806 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5807 | return false; |
| 5808 | } |
| 5809 | } |
| 5810 | break; |
| 5811 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5812 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5813 | { |
| 5814 | if (level != 0) |
| 5815 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5816 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5817 | return false; |
| 5818 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 5819 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5820 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5821 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5822 | return false; |
| 5823 | } |
| 5824 | } |
| 5825 | break; |
| 5826 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5827 | case TextureTarget::CubeMapNegativeX: |
| 5828 | case TextureTarget::CubeMapNegativeY: |
| 5829 | case TextureTarget::CubeMapNegativeZ: |
| 5830 | case TextureTarget::CubeMapPositiveX: |
| 5831 | case TextureTarget::CubeMapPositiveY: |
| 5832 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5833 | { |
| 5834 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 5835 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5836 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5837 | return false; |
| 5838 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 5839 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5840 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5841 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5842 | return false; |
| 5843 | } |
| 5844 | } |
| 5845 | break; |
| 5846 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5847 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5848 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 5849 | if (context->getClientVersion() < ES_3_1 && |
| 5850 | !context->getExtensions().textureMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5851 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5852 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5853 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5854 | return false; |
| 5855 | } |
| 5856 | |
| 5857 | if (level != 0) |
| 5858 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5859 | context->validationError(GL_INVALID_VALUE, kLevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5860 | return false; |
| 5861 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 5862 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5863 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5864 | context->validationError(GL_INVALID_OPERATION, kTextureTargetMismatch); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5865 | return false; |
| 5866 | } |
| 5867 | } |
| 5868 | break; |
| 5869 | |
| 5870 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5871 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5872 | return false; |
| 5873 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5874 | } |
| 5875 | |
| 5876 | return true; |
| 5877 | } |
| 5878 | |
| 5879 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 5880 | { |
| 5881 | return ValidateGenOrDelete(context, n); |
| 5882 | } |
| 5883 | |
| 5884 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 5885 | { |
| 5886 | return ValidateGenOrDelete(context, n); |
| 5887 | } |
| 5888 | |
| 5889 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 5890 | { |
| 5891 | return ValidateGenOrDelete(context, n); |
| 5892 | } |
| 5893 | |
| 5894 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 5895 | { |
| 5896 | return ValidateGenOrDelete(context, n); |
| 5897 | } |
| 5898 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5899 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5900 | { |
| 5901 | if (!ValidTextureTarget(context, target)) |
| 5902 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5903 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5904 | return false; |
| 5905 | } |
| 5906 | |
| 5907 | Texture *texture = context->getTargetTexture(target); |
| 5908 | |
| 5909 | if (texture == nullptr) |
| 5910 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5911 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5912 | return false; |
| 5913 | } |
| 5914 | |
| 5915 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 5916 | |
| 5917 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 5918 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 5919 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 5920 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5921 | context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5922 | return false; |
| 5923 | } |
| 5924 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5925 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 5926 | ? TextureTarget::CubeMapPositiveX |
| 5927 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 5928 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 5929 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 5930 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5931 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5932 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5933 | return false; |
| 5934 | } |
| 5935 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 5936 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 5937 | bool formatUnsized = !format.sized; |
| 5938 | bool formatColorRenderableAndFilterable = |
| 5939 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 5940 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 5941 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5942 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5943 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5944 | return false; |
| 5945 | } |
| 5946 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 5947 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 5948 | // generation |
| 5949 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 5950 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5951 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 5952 | return false; |
| 5953 | } |
| 5954 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 5955 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 5956 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 5957 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5958 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5959 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5960 | return false; |
| 5961 | } |
| 5962 | |
| 5963 | // Non-power of 2 ES2 check |
| 5964 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 5965 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 5966 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 5967 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5968 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 5969 | target == TextureType::CubeMap); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5970 | context->validationError(GL_INVALID_OPERATION, kTextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5971 | return false; |
| 5972 | } |
| 5973 | |
| 5974 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5975 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5976 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5977 | context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5978 | return false; |
| 5979 | } |
| 5980 | |
James Darpinian | 83b2f0e | 2018-11-27 15:56:01 -0800 | [diff] [blame] | 5981 | if (context->getExtensions().webglCompatibility && |
| 5982 | (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 || |
| 5983 | texture->getHeight(baseTarget, effectiveBaseLevel) == 0)) |
| 5984 | { |
| 5985 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize); |
| 5986 | return false; |
| 5987 | } |
| 5988 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5989 | return true; |
| 5990 | } |
| 5991 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5992 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5993 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5994 | GLenum pname, |
| 5995 | GLint *params) |
| 5996 | { |
| 5997 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 5998 | } |
| 5999 | |
| 6000 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6001 | GLenum target, |
| 6002 | GLenum pname, |
| 6003 | GLint *params) |
| 6004 | { |
| 6005 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6006 | } |
| 6007 | |
| 6008 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 6009 | { |
| 6010 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6011 | } |
| 6012 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6013 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6014 | { |
| 6015 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6016 | } |
| 6017 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6018 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6019 | { |
| 6020 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6021 | } |
| 6022 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6023 | bool ValidateGetTexParameterIivOES(Context *context, |
| 6024 | TextureType target, |
| 6025 | GLenum pname, |
| 6026 | GLint *params) |
| 6027 | { |
| 6028 | if (context->getClientMajorVersion() < 3) |
| 6029 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6030 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6031 | return false; |
| 6032 | } |
| 6033 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6034 | } |
| 6035 | |
| 6036 | bool ValidateGetTexParameterIuivOES(Context *context, |
| 6037 | TextureType target, |
| 6038 | GLenum pname, |
| 6039 | GLuint *params) |
| 6040 | { |
| 6041 | if (context->getClientMajorVersion() < 3) |
| 6042 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6043 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6044 | return false; |
| 6045 | } |
| 6046 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6047 | } |
| 6048 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6049 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 6050 | { |
| 6051 | return ValidateGetUniformBase(context, program, location); |
| 6052 | } |
| 6053 | |
| 6054 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 6055 | { |
| 6056 | return ValidateGetUniformBase(context, program, location); |
| 6057 | } |
| 6058 | |
| 6059 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6060 | { |
| 6061 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6062 | } |
| 6063 | |
| 6064 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6065 | { |
| 6066 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6067 | } |
| 6068 | |
| 6069 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6070 | { |
| 6071 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6072 | } |
| 6073 | |
| 6074 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6075 | { |
| 6076 | if (!ValidCap(context, cap, true)) |
| 6077 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6078 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6079 | return false; |
| 6080 | } |
| 6081 | |
| 6082 | return true; |
| 6083 | } |
| 6084 | |
| 6085 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 6086 | { |
| 6087 | if (context->hasActiveTransformFeedback(program)) |
| 6088 | { |
| 6089 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6090 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackActiveDuringLink); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6091 | return false; |
| 6092 | } |
| 6093 | |
| 6094 | Program *programObject = GetValidProgram(context, program); |
| 6095 | if (!programObject) |
| 6096 | { |
| 6097 | return false; |
| 6098 | } |
| 6099 | |
| 6100 | return true; |
| 6101 | } |
| 6102 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6103 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6104 | GLint x, |
| 6105 | GLint y, |
| 6106 | GLsizei width, |
| 6107 | GLsizei height, |
| 6108 | GLenum format, |
| 6109 | GLenum type, |
| 6110 | void *pixels) |
| 6111 | { |
| 6112 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6113 | nullptr, pixels); |
| 6114 | } |
| 6115 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6116 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6117 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6118 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6119 | } |
| 6120 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6121 | bool ValidateTexParameterfv(Context *context, |
| 6122 | TextureType target, |
| 6123 | GLenum pname, |
| 6124 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6125 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6126 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6127 | } |
| 6128 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6129 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6130 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6131 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6132 | } |
| 6133 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6134 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6135 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6136 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6137 | } |
| 6138 | |
| 6139 | bool ValidateTexParameterIivOES(Context *context, |
| 6140 | TextureType target, |
| 6141 | GLenum pname, |
| 6142 | const GLint *params) |
| 6143 | { |
| 6144 | if (context->getClientMajorVersion() < 3) |
| 6145 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6146 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6147 | return false; |
| 6148 | } |
| 6149 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6150 | } |
| 6151 | |
| 6152 | bool ValidateTexParameterIuivOES(Context *context, |
| 6153 | TextureType target, |
| 6154 | GLenum pname, |
| 6155 | const GLuint *params) |
| 6156 | { |
| 6157 | if (context->getClientMajorVersion() < 3) |
| 6158 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6159 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6160 | return false; |
| 6161 | } |
| 6162 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | bool ValidateUseProgram(Context *context, GLuint program) |
| 6166 | { |
| 6167 | if (program != 0) |
| 6168 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6169 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6170 | if (!programObject) |
| 6171 | { |
| 6172 | // ES 3.1.0 section 7.3 page 72 |
| 6173 | if (context->getShader(program)) |
| 6174 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6175 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6176 | return false; |
| 6177 | } |
| 6178 | else |
| 6179 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6180 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6181 | return false; |
| 6182 | } |
| 6183 | } |
| 6184 | if (!programObject->isLinked()) |
| 6185 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6186 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6187 | return false; |
| 6188 | } |
| 6189 | } |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 6190 | if (context->getState().isTransformFeedbackActiveUnpaused()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6191 | { |
| 6192 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6193 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackUseProgram); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6194 | return false; |
| 6195 | } |
| 6196 | |
| 6197 | return true; |
| 6198 | } |
| 6199 | |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6200 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences) |
| 6201 | { |
| 6202 | if (!context->getExtensions().fence) |
| 6203 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6204 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6205 | return false; |
| 6206 | } |
| 6207 | |
| 6208 | if (n < 0) |
| 6209 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6210 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6211 | return false; |
| 6212 | } |
| 6213 | |
| 6214 | return true; |
| 6215 | } |
| 6216 | |
| 6217 | bool ValidateFinishFenceNV(Context *context, GLuint fence) |
| 6218 | { |
| 6219 | if (!context->getExtensions().fence) |
| 6220 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6221 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6222 | return false; |
| 6223 | } |
| 6224 | |
| 6225 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6226 | |
| 6227 | if (fenceObject == nullptr) |
| 6228 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6229 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6230 | return false; |
| 6231 | } |
| 6232 | |
| 6233 | if (!fenceObject->isSet()) |
| 6234 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6235 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6236 | return false; |
| 6237 | } |
| 6238 | |
| 6239 | return true; |
| 6240 | } |
| 6241 | |
| 6242 | bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences) |
| 6243 | { |
| 6244 | if (!context->getExtensions().fence) |
| 6245 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6246 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6247 | return false; |
| 6248 | } |
| 6249 | |
| 6250 | if (n < 0) |
| 6251 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6252 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6253 | return false; |
| 6254 | } |
| 6255 | |
| 6256 | return true; |
| 6257 | } |
| 6258 | |
| 6259 | bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params) |
| 6260 | { |
| 6261 | if (!context->getExtensions().fence) |
| 6262 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6263 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6264 | return false; |
| 6265 | } |
| 6266 | |
| 6267 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6268 | |
| 6269 | if (fenceObject == nullptr) |
| 6270 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6271 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6272 | return false; |
| 6273 | } |
| 6274 | |
| 6275 | if (!fenceObject->isSet()) |
| 6276 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6277 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6278 | return false; |
| 6279 | } |
| 6280 | |
| 6281 | switch (pname) |
| 6282 | { |
| 6283 | case GL_FENCE_STATUS_NV: |
| 6284 | case GL_FENCE_CONDITION_NV: |
| 6285 | break; |
| 6286 | |
| 6287 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6288 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6289 | return false; |
| 6290 | } |
| 6291 | |
| 6292 | return true; |
| 6293 | } |
| 6294 | |
| 6295 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6296 | { |
| 6297 | if (!context->getExtensions().robustness) |
| 6298 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6299 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6300 | return false; |
| 6301 | } |
| 6302 | |
| 6303 | return true; |
| 6304 | } |
| 6305 | |
| 6306 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
| 6307 | GLuint shader, |
| 6308 | GLsizei bufsize, |
| 6309 | GLsizei *length, |
| 6310 | GLchar *source) |
| 6311 | { |
| 6312 | if (!context->getExtensions().translatedShaderSource) |
| 6313 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6314 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6315 | return false; |
| 6316 | } |
| 6317 | |
| 6318 | if (bufsize < 0) |
| 6319 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6320 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6321 | return false; |
| 6322 | } |
| 6323 | |
| 6324 | Shader *shaderObject = context->getShader(shader); |
| 6325 | |
| 6326 | if (!shaderObject) |
| 6327 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6328 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6329 | return false; |
| 6330 | } |
| 6331 | |
| 6332 | return true; |
| 6333 | } |
| 6334 | |
| 6335 | bool ValidateIsFenceNV(Context *context, GLuint fence) |
| 6336 | { |
| 6337 | if (!context->getExtensions().fence) |
| 6338 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6339 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6340 | return false; |
| 6341 | } |
| 6342 | |
| 6343 | return true; |
| 6344 | } |
| 6345 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6346 | bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition) |
| 6347 | { |
| 6348 | if (!context->getExtensions().fence) |
| 6349 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6350 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6351 | return false; |
| 6352 | } |
| 6353 | |
| 6354 | if (condition != GL_ALL_COMPLETED_NV) |
| 6355 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6356 | context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6357 | return false; |
| 6358 | } |
| 6359 | |
| 6360 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6361 | |
| 6362 | if (fenceObject == nullptr) |
| 6363 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6364 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6365 | return false; |
| 6366 | } |
| 6367 | |
| 6368 | return true; |
| 6369 | } |
| 6370 | |
| 6371 | bool ValidateTestFenceNV(Context *context, GLuint fence) |
| 6372 | { |
| 6373 | if (!context->getExtensions().fence) |
| 6374 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6375 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6376 | return false; |
| 6377 | } |
| 6378 | |
| 6379 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6380 | |
| 6381 | if (fenceObject == nullptr) |
| 6382 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6383 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6384 | return false; |
| 6385 | } |
| 6386 | |
| 6387 | if (fenceObject->isSet() != GL_TRUE) |
| 6388 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6389 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6390 | return false; |
| 6391 | } |
| 6392 | |
| 6393 | return true; |
| 6394 | } |
| 6395 | |
| 6396 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6397 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6398 | GLsizei levels, |
| 6399 | GLenum internalformat, |
| 6400 | GLsizei width, |
| 6401 | GLsizei height) |
| 6402 | { |
| 6403 | if (!context->getExtensions().textureStorage) |
| 6404 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6405 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6406 | return false; |
| 6407 | } |
| 6408 | |
| 6409 | if (context->getClientMajorVersion() < 3) |
| 6410 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6411 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6412 | height); |
| 6413 | } |
| 6414 | |
| 6415 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6416 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6417 | 1); |
| 6418 | } |
| 6419 | |
| 6420 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 6421 | { |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 6422 | if (!context->getExtensions().instancedArraysANGLE) |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6423 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6424 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6425 | return false; |
| 6426 | } |
| 6427 | |
| 6428 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6429 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6430 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6431 | return false; |
| 6432 | } |
| 6433 | |
| 6434 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 6435 | { |
| 6436 | if (index == 0 && divisor != 0) |
| 6437 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6438 | context->validationError(GL_INVALID_OPERATION, kAttributeZeroRequiresDivisorLimitation); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6439 | |
| 6440 | // We also output an error message to the debugger window if tracing is active, so |
| 6441 | // that developers can see the error message. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6442 | ERR() << kAttributeZeroRequiresDivisorLimitation; |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6443 | return false; |
| 6444 | } |
| 6445 | } |
| 6446 | |
| 6447 | return true; |
| 6448 | } |
| 6449 | |
Jonah Ryan-Davis | 2b0553c | 2019-02-08 10:07:21 -0500 | [diff] [blame] | 6450 | bool ValidateVertexAttribDivisorEXT(Context *context, GLuint index, GLuint divisor) |
| 6451 | { |
| 6452 | if (!context->getExtensions().instancedArraysEXT) |
| 6453 | { |
| 6454 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6455 | return false; |
| 6456 | } |
| 6457 | |
| 6458 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6459 | { |
| 6460 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
| 6461 | return false; |
| 6462 | } |
| 6463 | |
| 6464 | return true; |
| 6465 | } |
| 6466 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6467 | bool ValidateTexImage3DOES(Context *context, |
| 6468 | GLenum target, |
| 6469 | GLint level, |
| 6470 | GLenum internalformat, |
| 6471 | GLsizei width, |
| 6472 | GLsizei height, |
| 6473 | GLsizei depth, |
| 6474 | GLint border, |
| 6475 | GLenum format, |
| 6476 | GLenum type, |
| 6477 | const void *pixels) |
| 6478 | { |
| 6479 | UNIMPLEMENTED(); // FIXME |
| 6480 | return false; |
| 6481 | } |
| 6482 | |
| 6483 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 6484 | { |
| 6485 | if (!context->getExtensions().debugMarker) |
| 6486 | { |
| 6487 | // The debug marker calls should not set error state |
| 6488 | // 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] | 6489 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6490 | return false; |
| 6491 | } |
| 6492 | |
| 6493 | return true; |
| 6494 | } |
| 6495 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6496 | bool ValidateTexStorage1DEXT(Context *context, |
| 6497 | GLenum target, |
| 6498 | GLsizei levels, |
| 6499 | GLenum internalformat, |
| 6500 | GLsizei width) |
| 6501 | { |
| 6502 | UNIMPLEMENTED(); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6503 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6504 | return false; |
| 6505 | } |
| 6506 | |
| 6507 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6508 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6509 | GLsizei levels, |
| 6510 | GLenum internalformat, |
| 6511 | GLsizei width, |
| 6512 | GLsizei height, |
| 6513 | GLsizei depth) |
| 6514 | { |
| 6515 | if (!context->getExtensions().textureStorage) |
| 6516 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6517 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6518 | return false; |
| 6519 | } |
| 6520 | |
| 6521 | if (context->getClientMajorVersion() < 3) |
| 6522 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6523 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6524 | return false; |
| 6525 | } |
| 6526 | |
| 6527 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 6528 | depth); |
| 6529 | } |
| 6530 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6531 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 6532 | { |
| 6533 | if (!context->getExtensions().parallelShaderCompile) |
| 6534 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6535 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6536 | return false; |
| 6537 | } |
| 6538 | return true; |
| 6539 | } |
| 6540 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6541 | bool ValidateMultiDrawArraysANGLE(Context *context, |
| 6542 | PrimitiveMode mode, |
| 6543 | const GLint *firsts, |
| 6544 | const GLsizei *counts, |
| 6545 | GLsizei drawcount) |
| 6546 | { |
| 6547 | if (!context->getExtensions().multiDraw) |
| 6548 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6549 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6550 | return false; |
| 6551 | } |
| 6552 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6553 | { |
| 6554 | if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID])) |
| 6555 | { |
| 6556 | return false; |
| 6557 | } |
| 6558 | } |
| 6559 | return true; |
| 6560 | } |
| 6561 | |
| 6562 | bool ValidateMultiDrawElementsANGLE(Context *context, |
| 6563 | PrimitiveMode mode, |
| 6564 | const GLsizei *counts, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 6565 | DrawElementsType type, |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 6566 | const GLvoid *const *indices, |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6567 | GLsizei drawcount) |
| 6568 | { |
| 6569 | if (!context->getExtensions().multiDraw) |
| 6570 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6571 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6572 | return false; |
| 6573 | } |
| 6574 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6575 | { |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 6576 | if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID])) |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6577 | { |
| 6578 | return false; |
| 6579 | } |
| 6580 | } |
| 6581 | return true; |
| 6582 | } |
| 6583 | |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 6584 | bool ValidateProvokingVertexANGLE(Context *context, ProvokingVertex modePacked) |
| 6585 | { |
| 6586 | if (!context->getExtensions().provokingVertex) |
| 6587 | { |
| 6588 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
| 6589 | return false; |
| 6590 | } |
| 6591 | |
| 6592 | switch (modePacked) |
| 6593 | { |
| 6594 | case ProvokingVertex::FirstVertexConvention: |
| 6595 | case ProvokingVertex::LastVertexConvention: |
| 6596 | break; |
| 6597 | default: |
| 6598 | context->validationError(GL_INVALID_ENUM, kInvalidProvokingVertex); |
| 6599 | return false; |
| 6600 | } |
| 6601 | |
| 6602 | return true; |
| 6603 | } |
| 6604 | |
Jamie Madill | a541048 | 2019-01-31 19:55:55 -0500 | [diff] [blame] | 6605 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 6606 | { |
| 6607 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 6608 | |
| 6609 | switch (target) |
| 6610 | { |
| 6611 | case TextureType::Rectangle: |
| 6612 | ASSERT(!context->getExtensions().textureRectangle); |
| 6613 | context->validationError(GL_INVALID_ENUM, kTextureRectangleNotSupported); |
| 6614 | break; |
| 6615 | |
| 6616 | case TextureType::_3D: |
| 6617 | case TextureType::_2DArray: |
| 6618 | ASSERT(context->getClientMajorVersion() < 3); |
| 6619 | context->validationError(GL_INVALID_ENUM, kES3Required); |
| 6620 | break; |
| 6621 | |
| 6622 | case TextureType::_2DMultisample: |
| 6623 | ASSERT(context->getClientVersion() < Version(3, 1) && |
| 6624 | !context->getExtensions().textureMultisample); |
| 6625 | context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required); |
| 6626 | break; |
| 6627 | |
| 6628 | case TextureType::_2DMultisampleArray: |
| 6629 | ASSERT(!context->getExtensions().textureStorageMultisample2DArray); |
| 6630 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
| 6631 | break; |
| 6632 | |
| 6633 | case TextureType::External: |
| 6634 | ASSERT(!context->getExtensions().eglImageExternal && |
| 6635 | !context->getExtensions().eglStreamConsumerExternal); |
| 6636 | context->validationError(GL_INVALID_ENUM, kExternalTextureNotSupported); |
| 6637 | break; |
| 6638 | |
| 6639 | default: |
| 6640 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
| 6641 | } |
| 6642 | } |
| 6643 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6644 | } // namespace gl |