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 | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 59 | if (context->getGLState().isScissorTestEnabled()) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 60 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 61 | const Rectangle &scissor = context->getGLState().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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 99 | context->validationError(GL_INVALID_OPERATION, |
| 100 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 101 | return false; |
| 102 | } |
| 103 | |
| 104 | if (paths == nullptr) |
| 105 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 106 | context->validationError(GL_INVALID_VALUE, "No path name array."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 107 | return false; |
| 108 | } |
| 109 | |
| 110 | if (numPaths < 0) |
| 111 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 112 | context->validationError(GL_INVALID_VALUE, "Invalid (negative) numPaths."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 113 | return false; |
| 114 | } |
| 115 | |
| 116 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths)) |
| 117 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 118 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 119 | return false; |
| 120 | } |
| 121 | |
| 122 | std::uint32_t pathNameTypeSize = 0; |
| 123 | std::uint32_t componentCount = 0; |
| 124 | |
| 125 | switch (pathNameType) |
| 126 | { |
| 127 | case GL_UNSIGNED_BYTE: |
| 128 | pathNameTypeSize = sizeof(GLubyte); |
| 129 | if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase)) |
| 130 | return false; |
| 131 | break; |
| 132 | |
| 133 | case GL_BYTE: |
| 134 | pathNameTypeSize = sizeof(GLbyte); |
| 135 | if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase)) |
| 136 | return false; |
| 137 | break; |
| 138 | |
| 139 | case GL_UNSIGNED_SHORT: |
| 140 | pathNameTypeSize = sizeof(GLushort); |
| 141 | if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase)) |
| 142 | return false; |
| 143 | break; |
| 144 | |
| 145 | case GL_SHORT: |
| 146 | pathNameTypeSize = sizeof(GLshort); |
| 147 | if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase)) |
| 148 | return false; |
| 149 | break; |
| 150 | |
| 151 | case GL_UNSIGNED_INT: |
| 152 | pathNameTypeSize = sizeof(GLuint); |
| 153 | if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase)) |
| 154 | return false; |
| 155 | break; |
| 156 | |
| 157 | case GL_INT: |
| 158 | pathNameTypeSize = sizeof(GLint); |
| 159 | if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase)) |
| 160 | return false; |
| 161 | break; |
| 162 | |
| 163 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 164 | context->validationError(GL_INVALID_ENUM, "Invalid path name type."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 165 | return false; |
| 166 | } |
| 167 | |
| 168 | switch (transformType) |
| 169 | { |
| 170 | case GL_NONE: |
| 171 | componentCount = 0; |
| 172 | break; |
| 173 | case GL_TRANSLATE_X_CHROMIUM: |
| 174 | case GL_TRANSLATE_Y_CHROMIUM: |
| 175 | componentCount = 1; |
| 176 | break; |
| 177 | case GL_TRANSLATE_2D_CHROMIUM: |
| 178 | componentCount = 2; |
| 179 | break; |
| 180 | case GL_TRANSLATE_3D_CHROMIUM: |
| 181 | componentCount = 3; |
| 182 | break; |
| 183 | case GL_AFFINE_2D_CHROMIUM: |
| 184 | case GL_TRANSPOSE_AFFINE_2D_CHROMIUM: |
| 185 | componentCount = 6; |
| 186 | break; |
| 187 | case GL_AFFINE_3D_CHROMIUM: |
| 188 | case GL_TRANSPOSE_AFFINE_3D_CHROMIUM: |
| 189 | componentCount = 12; |
| 190 | break; |
| 191 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 192 | context->validationError(GL_INVALID_ENUM, "Invalid transformation."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 193 | return false; |
| 194 | } |
| 195 | if (componentCount != 0 && transformValues == nullptr) |
| 196 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 197 | context->validationError(GL_INVALID_VALUE, "No transform array given."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 198 | return false; |
| 199 | } |
| 200 | |
| 201 | angle::CheckedNumeric<std::uint32_t> checkedSize(0); |
| 202 | checkedSize += (numPaths * pathNameTypeSize); |
| 203 | checkedSize += (numPaths * sizeof(GLfloat) * componentCount); |
| 204 | if (!checkedSize.IsValid()) |
| 205 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 206 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 207 | return false; |
| 208 | } |
| 209 | |
| 210 | return true; |
| 211 | } |
| 212 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 213 | bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 214 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 215 | // Table 1.1 from the CHROMIUM_copy_texture spec |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 216 | switch (GetUnsizedFormat(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 217 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 218 | case GL_RED: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 219 | case GL_ALPHA: |
| 220 | case GL_LUMINANCE: |
| 221 | case GL_LUMINANCE_ALPHA: |
| 222 | case GL_RGB: |
| 223 | case GL_RGBA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 224 | case GL_RGB8: |
| 225 | case GL_RGBA8: |
| 226 | case GL_BGRA_EXT: |
| 227 | case GL_BGRA8_EXT: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 228 | return true; |
| 229 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 230 | default: |
| 231 | return false; |
| 232 | } |
| 233 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 234 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 235 | bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat) |
| 236 | { |
| 237 | return IsValidCopyTextureSourceInternalFormatEnum(internalFormat); |
| 238 | } |
| 239 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 240 | bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat) |
| 241 | { |
| 242 | // Table 1.0 from the CHROMIUM_copy_texture spec |
| 243 | switch (internalFormat) |
| 244 | { |
| 245 | case GL_RGB: |
| 246 | case GL_RGBA: |
| 247 | case GL_RGB8: |
| 248 | case GL_RGBA8: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 249 | case GL_BGRA_EXT: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 250 | case GL_BGRA8_EXT: |
| 251 | case GL_SRGB_EXT: |
| 252 | case GL_SRGB_ALPHA_EXT: |
| 253 | case GL_R8: |
| 254 | case GL_R8UI: |
| 255 | case GL_RG8: |
| 256 | case GL_RG8UI: |
| 257 | case GL_SRGB8: |
| 258 | case GL_RGB565: |
| 259 | case GL_RGB8UI: |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 260 | case GL_RGB10_A2: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 261 | case GL_SRGB8_ALPHA8: |
| 262 | case GL_RGB5_A1: |
| 263 | case GL_RGBA4: |
| 264 | case GL_RGBA8UI: |
| 265 | case GL_RGB9_E5: |
| 266 | case GL_R16F: |
| 267 | case GL_R32F: |
| 268 | case GL_RG16F: |
| 269 | case GL_RG32F: |
| 270 | case GL_RGB16F: |
| 271 | case GL_RGB32F: |
| 272 | case GL_RGBA16F: |
| 273 | case GL_RGBA32F: |
| 274 | case GL_R11F_G11F_B10F: |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 275 | case GL_LUMINANCE: |
| 276 | case GL_LUMINANCE_ALPHA: |
| 277 | case GL_ALPHA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 278 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 279 | |
| 280 | default: |
| 281 | return false; |
| 282 | } |
| 283 | } |
| 284 | |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 285 | bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat) |
| 286 | { |
| 287 | return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat); |
| 288 | } |
| 289 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 290 | bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type) |
| 291 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 292 | if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 293 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 294 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 295 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 298 | if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat)) |
| 299 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 300 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 301 | return false; |
| 302 | } |
| 303 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 304 | const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type); |
| 305 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 306 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 307 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 308 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | return true; |
| 312 | } |
| 313 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 314 | bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 315 | { |
| 316 | switch (target) |
| 317 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 318 | case TextureTarget::_2D: |
| 319 | case TextureTarget::CubeMapNegativeX: |
| 320 | case TextureTarget::CubeMapNegativeY: |
| 321 | case TextureTarget::CubeMapNegativeZ: |
| 322 | case TextureTarget::CubeMapPositiveX: |
| 323 | case TextureTarget::CubeMapPositiveY: |
| 324 | case TextureTarget::CubeMapPositiveZ: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 325 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 326 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 327 | case TextureTarget::Rectangle: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 328 | return context->getExtensions().textureRectangle; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 329 | |
| 330 | default: |
| 331 | return false; |
| 332 | } |
| 333 | } |
| 334 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 335 | bool IsValidCopyTextureDestinationTarget(Context *context, |
| 336 | TextureType textureType, |
| 337 | TextureTarget target) |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 338 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 339 | return TextureTargetToType(target) == textureType; |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 340 | } |
| 341 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 342 | bool IsValidCopyTextureSourceTarget(Context *context, TextureType type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 343 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 344 | switch (type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 345 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 346 | case TextureType::_2D: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 347 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 348 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 349 | return context->getExtensions().textureRectangle; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 350 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 351 | // TODO(geofflang): accept GL_TEXTURE_EXTERNAL_OES if the texture_external extension is |
| 352 | // supported |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 353 | |
| 354 | default: |
| 355 | return false; |
| 356 | } |
| 357 | } |
| 358 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 359 | bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 360 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 361 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 362 | { |
| 363 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 366 | if (level > 0 && context->getClientVersion() < ES_3_0) |
| 367 | { |
| 368 | return false; |
| 369 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 370 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 371 | return true; |
| 372 | } |
| 373 | |
| 374 | bool IsValidCopyTextureDestinationLevel(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 375 | TextureType type, |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 376 | GLint level, |
| 377 | GLsizei width, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 378 | GLsizei height, |
| 379 | bool isSubImage) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 380 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 381 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 382 | { |
| 383 | return false; |
| 384 | } |
| 385 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 386 | if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage)) |
| 387 | { |
| 388 | return false; |
| 389 | } |
| 390 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 391 | const Caps &caps = context->getCaps(); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 392 | switch (type) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 393 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 394 | case TextureType::_2D: |
| 395 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 396 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
| 397 | case TextureType::Rectangle: |
| 398 | ASSERT(level == 0); |
| 399 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 400 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 401 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 402 | case TextureType::CubeMap: |
| 403 | return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) && |
| 404 | static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level); |
| 405 | default: |
| 406 | return true; |
| 407 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 410 | bool IsValidStencilFunc(GLenum func) |
| 411 | { |
| 412 | switch (func) |
| 413 | { |
| 414 | case GL_NEVER: |
| 415 | case GL_ALWAYS: |
| 416 | case GL_LESS: |
| 417 | case GL_LEQUAL: |
| 418 | case GL_EQUAL: |
| 419 | case GL_GEQUAL: |
| 420 | case GL_GREATER: |
| 421 | case GL_NOTEQUAL: |
| 422 | return true; |
| 423 | |
| 424 | default: |
| 425 | return false; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | bool IsValidStencilFace(GLenum face) |
| 430 | { |
| 431 | switch (face) |
| 432 | { |
| 433 | case GL_FRONT: |
| 434 | case GL_BACK: |
| 435 | case GL_FRONT_AND_BACK: |
| 436 | return true; |
| 437 | |
| 438 | default: |
| 439 | return false; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | bool IsValidStencilOp(GLenum op) |
| 444 | { |
| 445 | switch (op) |
| 446 | { |
| 447 | case GL_ZERO: |
| 448 | case GL_KEEP: |
| 449 | case GL_REPLACE: |
| 450 | case GL_INCR: |
| 451 | case GL_DECR: |
| 452 | case GL_INVERT: |
| 453 | case GL_INCR_WRAP: |
| 454 | case GL_DECR_WRAP: |
| 455 | return true; |
| 456 | |
| 457 | default: |
| 458 | return false; |
| 459 | } |
| 460 | } |
| 461 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 462 | bool ValidateES2CopyTexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 463 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 464 | GLint level, |
| 465 | GLenum internalformat, |
| 466 | bool isSubImage, |
| 467 | GLint xoffset, |
| 468 | GLint yoffset, |
| 469 | GLint x, |
| 470 | GLint y, |
| 471 | GLsizei width, |
| 472 | GLsizei height, |
| 473 | GLint border) |
| 474 | { |
| 475 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 476 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 477 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 478 | return false; |
| 479 | } |
| 480 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 481 | TextureType texType = TextureTargetToType(target); |
| 482 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 483 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 484 | context->validationError(GL_INVALID_VALUE, "Invalid texture dimensions."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 485 | return false; |
| 486 | } |
| 487 | |
| 488 | Format textureFormat = Format::Invalid(); |
| 489 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 490 | xoffset, yoffset, 0, x, y, width, height, border, |
| 491 | &textureFormat)) |
| 492 | { |
| 493 | return false; |
| 494 | } |
| 495 | |
| 496 | const gl::Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
| 497 | GLenum colorbufferFormat = |
| 498 | framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat; |
| 499 | const auto &formatInfo = *textureFormat.info; |
| 500 | |
| 501 | // [OpenGL ES 2.0.24] table 3.9 |
| 502 | if (isSubImage) |
| 503 | { |
| 504 | switch (formatInfo.format) |
| 505 | { |
| 506 | case GL_ALPHA: |
| 507 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 508 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 509 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 510 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 511 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 512 | return false; |
| 513 | } |
| 514 | break; |
| 515 | case GL_LUMINANCE: |
| 516 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 517 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 518 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 519 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT && |
| 520 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 521 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 522 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 523 | return false; |
| 524 | } |
| 525 | break; |
| 526 | case GL_RED_EXT: |
| 527 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 528 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 529 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 530 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F && |
| 531 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 532 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 533 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 534 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 535 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 536 | return false; |
| 537 | } |
| 538 | break; |
| 539 | case GL_RG_EXT: |
| 540 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 541 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 542 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 543 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 544 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 545 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 546 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 547 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 548 | return false; |
| 549 | } |
| 550 | break; |
| 551 | case GL_RGB: |
| 552 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 553 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 554 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 555 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 556 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 557 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 558 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 559 | return false; |
| 560 | } |
| 561 | break; |
| 562 | case GL_LUMINANCE_ALPHA: |
| 563 | case GL_RGBA: |
| 564 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 565 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F && |
| 566 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 567 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 568 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 569 | return false; |
| 570 | } |
| 571 | break; |
| 572 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 573 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 574 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 575 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 576 | case GL_ETC1_RGB8_OES: |
| 577 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 578 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 579 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 580 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 581 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 582 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 583 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 584 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 585 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 586 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 587 | return false; |
| 588 | case GL_DEPTH_COMPONENT: |
| 589 | case GL_DEPTH_STENCIL_OES: |
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 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 593 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 594 | return false; |
| 595 | } |
| 596 | |
| 597 | if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat) |
| 598 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 599 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 600 | return false; |
| 601 | } |
| 602 | } |
| 603 | else |
| 604 | { |
| 605 | switch (internalformat) |
| 606 | { |
| 607 | case GL_ALPHA: |
| 608 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
| 609 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 610 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 611 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 612 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 613 | return false; |
| 614 | } |
| 615 | break; |
| 616 | case GL_LUMINANCE: |
| 617 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 618 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 619 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 620 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 621 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 622 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 623 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 624 | return false; |
| 625 | } |
| 626 | break; |
| 627 | case GL_RED_EXT: |
| 628 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 629 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 630 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 631 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 632 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 633 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 634 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 635 | return false; |
| 636 | } |
| 637 | break; |
| 638 | case GL_RG_EXT: |
| 639 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 640 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 641 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 642 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 643 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 644 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 645 | return false; |
| 646 | } |
| 647 | break; |
| 648 | case GL_RGB: |
| 649 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 650 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 651 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 652 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 653 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 654 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 655 | return false; |
| 656 | } |
| 657 | break; |
| 658 | case GL_LUMINANCE_ALPHA: |
| 659 | case GL_RGBA: |
| 660 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 661 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 662 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 663 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 664 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 665 | return false; |
| 666 | } |
| 667 | break; |
| 668 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 669 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 670 | if (context->getExtensions().textureCompressionDXT1) |
| 671 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 672 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 673 | return false; |
| 674 | } |
| 675 | else |
| 676 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 677 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 678 | return false; |
| 679 | } |
| 680 | break; |
| 681 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 682 | if (context->getExtensions().textureCompressionDXT3) |
| 683 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 684 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 685 | return false; |
| 686 | } |
| 687 | else |
| 688 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 689 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 690 | return false; |
| 691 | } |
| 692 | break; |
| 693 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 694 | if (context->getExtensions().textureCompressionDXT5) |
| 695 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 696 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 697 | return false; |
| 698 | } |
| 699 | else |
| 700 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 701 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 702 | return false; |
| 703 | } |
| 704 | break; |
| 705 | case GL_ETC1_RGB8_OES: |
| 706 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 707 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 708 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 709 | return false; |
| 710 | } |
| 711 | else |
| 712 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 713 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 714 | return false; |
| 715 | } |
| 716 | break; |
| 717 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 718 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 719 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 720 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 721 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 722 | if (context->getExtensions().lossyETCDecode) |
| 723 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 724 | context->validationError(GL_INVALID_OPERATION, |
| 725 | "ETC lossy decode formats can't be copied to."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 726 | return false; |
| 727 | } |
| 728 | else |
| 729 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 730 | context->validationError(GL_INVALID_ENUM, |
| 731 | "ANGLE_lossy_etc_decode extension is not supported."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 732 | return false; |
| 733 | } |
| 734 | break; |
| 735 | case GL_DEPTH_COMPONENT: |
| 736 | case GL_DEPTH_COMPONENT16: |
| 737 | case GL_DEPTH_COMPONENT32_OES: |
| 738 | case GL_DEPTH_STENCIL_OES: |
| 739 | case GL_DEPTH24_STENCIL8_OES: |
| 740 | if (context->getExtensions().depthTextures) |
| 741 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 742 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 743 | return false; |
| 744 | } |
| 745 | else |
| 746 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 747 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 748 | return false; |
| 749 | } |
| 750 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 751 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 752 | return false; |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 757 | return (width > 0 && height > 0); |
| 758 | } |
| 759 | |
| 760 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 761 | { |
| 762 | switch (cap) |
| 763 | { |
| 764 | // EXT_multisample_compatibility |
| 765 | case GL_MULTISAMPLE_EXT: |
| 766 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 767 | return context->getExtensions().multisampleCompatibility; |
| 768 | |
| 769 | case GL_CULL_FACE: |
| 770 | case GL_POLYGON_OFFSET_FILL: |
| 771 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 772 | case GL_SAMPLE_COVERAGE: |
| 773 | case GL_SCISSOR_TEST: |
| 774 | case GL_STENCIL_TEST: |
| 775 | case GL_DEPTH_TEST: |
| 776 | case GL_BLEND: |
| 777 | case GL_DITHER: |
| 778 | return true; |
| 779 | |
| 780 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 781 | case GL_RASTERIZER_DISCARD: |
| 782 | return (context->getClientMajorVersion() >= 3); |
| 783 | |
| 784 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 785 | case GL_DEBUG_OUTPUT: |
| 786 | return context->getExtensions().debug; |
| 787 | |
| 788 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 789 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 790 | |
| 791 | case GL_CLIENT_ARRAYS_ANGLE: |
| 792 | return queryOnly && context->getExtensions().clientArrays; |
| 793 | |
| 794 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 795 | return context->getExtensions().sRGBWriteControl; |
| 796 | |
| 797 | case GL_SAMPLE_MASK: |
| 798 | return context->getClientVersion() >= Version(3, 1); |
| 799 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 800 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 801 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 802 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 803 | // GLES1 emulation: GLES1-specific caps |
| 804 | case GL_ALPHA_TEST: |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 805 | case GL_VERTEX_ARRAY: |
| 806 | case GL_NORMAL_ARRAY: |
| 807 | case GL_COLOR_ARRAY: |
| 808 | case GL_TEXTURE_COORD_ARRAY: |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 809 | case GL_TEXTURE_2D: |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 810 | case GL_LIGHTING: |
| 811 | case GL_LIGHT0: |
| 812 | case GL_LIGHT1: |
| 813 | case GL_LIGHT2: |
| 814 | case GL_LIGHT3: |
| 815 | case GL_LIGHT4: |
| 816 | case GL_LIGHT5: |
| 817 | case GL_LIGHT6: |
| 818 | case GL_LIGHT7: |
| 819 | case GL_NORMALIZE: |
| 820 | case GL_RESCALE_NORMAL: |
| 821 | case GL_COLOR_MATERIAL: |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 822 | case GL_CLIP_PLANE0: |
| 823 | case GL_CLIP_PLANE1: |
| 824 | case GL_CLIP_PLANE2: |
| 825 | case GL_CLIP_PLANE3: |
| 826 | case GL_CLIP_PLANE4: |
| 827 | case GL_CLIP_PLANE5: |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 828 | case GL_FOG: |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 829 | case GL_POINT_SMOOTH: |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 830 | case GL_LINE_SMOOTH: |
| 831 | case GL_COLOR_LOGIC_OP: |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 832 | return context->getClientVersion() < Version(2, 0); |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 833 | case GL_POINT_SIZE_ARRAY_OES: |
| 834 | return context->getClientVersion() < Version(2, 0) && |
| 835 | context->getExtensions().pointSizeArray; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 836 | case GL_TEXTURE_CUBE_MAP: |
| 837 | return context->getClientVersion() < Version(2, 0) && |
| 838 | context->getExtensions().textureCubeMap; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 839 | case GL_POINT_SPRITE_OES: |
| 840 | return context->getClientVersion() < Version(2, 0) && |
| 841 | context->getExtensions().pointSprite; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 842 | default: |
| 843 | return false; |
| 844 | } |
| 845 | } |
| 846 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 847 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 848 | // 3.1. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 849 | bool IsValidESSLCharacter(unsigned char c) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 850 | { |
| 851 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 852 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && |
| 853 | c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 854 | { |
| 855 | return true; |
| 856 | } |
| 857 | |
| 858 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 859 | if (c >= 9 && c <= 13) |
| 860 | { |
| 861 | return true; |
| 862 | } |
| 863 | |
| 864 | return false; |
| 865 | } |
| 866 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 867 | bool IsValidESSLString(const char *str, size_t len) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 868 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 869 | for (size_t i = 0; i < len; i++) |
| 870 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 871 | if (!IsValidESSLCharacter(str[i])) |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 872 | { |
| 873 | return false; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 878 | } |
| 879 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 880 | bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed) |
| 881 | { |
| 882 | enum class ParseState |
| 883 | { |
| 884 | // Have not seen an ASCII non-whitespace character yet on |
| 885 | // this line. Possible that we might see a preprocessor |
| 886 | // directive. |
| 887 | BEGINING_OF_LINE, |
| 888 | |
| 889 | // Have seen at least one ASCII non-whitespace character |
| 890 | // on this line. |
| 891 | MIDDLE_OF_LINE, |
| 892 | |
| 893 | // Handling a preprocessor directive. Passes through all |
| 894 | // characters up to the end of the line. Disables comment |
| 895 | // processing. |
| 896 | IN_PREPROCESSOR_DIRECTIVE, |
| 897 | |
| 898 | // Handling a single-line comment. The comment text is |
| 899 | // replaced with a single space. |
| 900 | IN_SINGLE_LINE_COMMENT, |
| 901 | |
| 902 | // Handling a multi-line comment. Newlines are passed |
| 903 | // through to preserve line numbers. |
| 904 | IN_MULTI_LINE_COMMENT |
| 905 | }; |
| 906 | |
| 907 | ParseState state = ParseState::BEGINING_OF_LINE; |
| 908 | size_t pos = 0; |
| 909 | |
| 910 | while (pos < len) |
| 911 | { |
| 912 | char c = str[pos]; |
| 913 | char next = pos + 1 < len ? str[pos + 1] : 0; |
| 914 | |
| 915 | // Check for newlines |
| 916 | if (c == '\n' || c == '\r') |
| 917 | { |
| 918 | if (state != ParseState::IN_MULTI_LINE_COMMENT) |
| 919 | { |
| 920 | state = ParseState::BEGINING_OF_LINE; |
| 921 | } |
| 922 | |
| 923 | pos++; |
| 924 | continue; |
| 925 | } |
| 926 | |
| 927 | switch (state) |
| 928 | { |
| 929 | case ParseState::BEGINING_OF_LINE: |
| 930 | if (c == ' ') |
| 931 | { |
| 932 | // Maintain the BEGINING_OF_LINE state until a non-space is seen |
| 933 | pos++; |
| 934 | } |
| 935 | else if (c == '#') |
| 936 | { |
| 937 | state = ParseState::IN_PREPROCESSOR_DIRECTIVE; |
| 938 | pos++; |
| 939 | } |
| 940 | else |
| 941 | { |
| 942 | // Don't advance, re-process this character with the MIDDLE_OF_LINE state |
| 943 | state = ParseState::MIDDLE_OF_LINE; |
| 944 | } |
| 945 | break; |
| 946 | |
| 947 | case ParseState::MIDDLE_OF_LINE: |
| 948 | if (c == '/' && next == '/') |
| 949 | { |
| 950 | state = ParseState::IN_SINGLE_LINE_COMMENT; |
| 951 | pos++; |
| 952 | } |
| 953 | else if (c == '/' && next == '*') |
| 954 | { |
| 955 | state = ParseState::IN_MULTI_LINE_COMMENT; |
| 956 | pos++; |
| 957 | } |
| 958 | else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r')) |
| 959 | { |
| 960 | // Skip line continuation characters |
| 961 | } |
| 962 | else if (!IsValidESSLCharacter(c)) |
| 963 | { |
| 964 | return false; |
| 965 | } |
| 966 | pos++; |
| 967 | break; |
| 968 | |
| 969 | case ParseState::IN_PREPROCESSOR_DIRECTIVE: |
Bryan Bernhart (Intel Americas Inc) | 335d8bf | 2017-10-23 15:41:43 -0700 | [diff] [blame] | 970 | // Line-continuation characters may not be permitted. |
| 971 | // Otherwise, just pass it through. Do not parse comments in this state. |
| 972 | if (!lineContinuationAllowed && c == '\\') |
| 973 | { |
| 974 | return false; |
| 975 | } |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 976 | pos++; |
| 977 | break; |
| 978 | |
| 979 | case ParseState::IN_SINGLE_LINE_COMMENT: |
| 980 | // Line-continuation characters are processed before comment processing. |
| 981 | // Advance string if a new line character is immediately behind |
| 982 | // line-continuation character. |
| 983 | if (c == '\\' && (next == '\n' || next == '\r')) |
| 984 | { |
| 985 | pos++; |
| 986 | } |
| 987 | pos++; |
| 988 | break; |
| 989 | |
| 990 | case ParseState::IN_MULTI_LINE_COMMENT: |
| 991 | if (c == '*' && next == '/') |
| 992 | { |
| 993 | state = ParseState::MIDDLE_OF_LINE; |
| 994 | pos++; |
| 995 | } |
| 996 | pos++; |
| 997 | break; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | return true; |
| 1002 | } |
| 1003 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1004 | bool ValidateWebGLNamePrefix(Context *context, const GLchar *name) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1005 | { |
| 1006 | ASSERT(context->isWebGL()); |
| 1007 | |
| 1008 | // WebGL 1.0 [Section 6.16] GLSL Constructs |
| 1009 | // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. |
| 1010 | if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0) |
| 1011 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1012 | context->validationError(GL_INVALID_OPERATION, kWebglBindAttribLocationReservedPrefix); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1013 | return false; |
| 1014 | } |
| 1015 | |
| 1016 | return true; |
| 1017 | } |
| 1018 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1019 | bool ValidateWebGLNameLength(Context *context, size_t length) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1020 | { |
| 1021 | ASSERT(context->isWebGL()); |
| 1022 | |
| 1023 | if (context->isWebGL1() && length > 256) |
| 1024 | { |
| 1025 | // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths |
| 1026 | // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute |
| 1027 | // locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1028 | context->validationError(GL_INVALID_VALUE, kWebglNameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1029 | |
| 1030 | return false; |
| 1031 | } |
| 1032 | else if (length > 1024) |
| 1033 | { |
| 1034 | // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of |
| 1035 | // uniform and attribute locations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1036 | context->validationError(GL_INVALID_VALUE, kWebgl2NameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1037 | return false; |
| 1038 | } |
| 1039 | |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1043 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 1044 | { |
| 1045 | if (!context->getExtensions().pathRendering) |
| 1046 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1047 | context->validationError(GL_INVALID_OPERATION, |
| 1048 | "GL_CHROMIUM_path_rendering is not available."); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1049 | return false; |
| 1050 | } |
| 1051 | |
| 1052 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 1053 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1054 | context->validationError(GL_INVALID_ENUM, kInvalidMatrixMode); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1055 | return false; |
| 1056 | } |
| 1057 | return true; |
| 1058 | } |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 1059 | |
| 1060 | bool ValidBlendFunc(const Context *context, GLenum val) |
| 1061 | { |
| 1062 | const gl::Extensions &ext = context->getExtensions(); |
| 1063 | |
| 1064 | // these are always valid for src and dst. |
| 1065 | switch (val) |
| 1066 | { |
| 1067 | case GL_ZERO: |
| 1068 | case GL_ONE: |
| 1069 | case GL_SRC_COLOR: |
| 1070 | case GL_ONE_MINUS_SRC_COLOR: |
| 1071 | case GL_DST_COLOR: |
| 1072 | case GL_ONE_MINUS_DST_COLOR: |
| 1073 | case GL_SRC_ALPHA: |
| 1074 | case GL_ONE_MINUS_SRC_ALPHA: |
| 1075 | case GL_DST_ALPHA: |
| 1076 | case GL_ONE_MINUS_DST_ALPHA: |
| 1077 | case GL_CONSTANT_COLOR: |
| 1078 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 1079 | case GL_CONSTANT_ALPHA: |
| 1080 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 1081 | return true; |
| 1082 | |
| 1083 | // EXT_blend_func_extended. |
| 1084 | case GL_SRC1_COLOR_EXT: |
| 1085 | case GL_SRC1_ALPHA_EXT: |
| 1086 | case GL_ONE_MINUS_SRC1_COLOR_EXT: |
| 1087 | case GL_ONE_MINUS_SRC1_ALPHA_EXT: |
| 1088 | case GL_SRC_ALPHA_SATURATE_EXT: |
| 1089 | return ext.blendFuncExtended; |
| 1090 | |
| 1091 | default: |
| 1092 | return false; |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | bool ValidSrcBlendFunc(const Context *context, GLenum val) |
| 1097 | { |
| 1098 | if (ValidBlendFunc(context, val)) |
| 1099 | return true; |
| 1100 | |
| 1101 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1102 | return true; |
| 1103 | |
| 1104 | return false; |
| 1105 | } |
| 1106 | |
| 1107 | bool ValidDstBlendFunc(const Context *context, GLenum val) |
| 1108 | { |
| 1109 | if (ValidBlendFunc(context, val)) |
| 1110 | return true; |
| 1111 | |
| 1112 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1113 | { |
| 1114 | if (context->getClientMajorVersion() >= 3) |
| 1115 | return true; |
| 1116 | } |
| 1117 | |
| 1118 | return false; |
| 1119 | } |
| 1120 | |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1121 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 1122 | { |
| 1123 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 1124 | |
| 1125 | switch (target) |
| 1126 | { |
| 1127 | case TextureType::Rectangle: |
| 1128 | ASSERT(!context->getExtensions().textureRectangle); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1129 | context->validationError(GL_INVALID_ENUM, |
| 1130 | "Context does not support GL_ANGLE_texture_rectangle"); |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1131 | break; |
| 1132 | |
| 1133 | case TextureType::_3D: |
| 1134 | case TextureType::_2DArray: |
| 1135 | ASSERT(context->getClientMajorVersion() < 3); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1136 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1137 | break; |
| 1138 | |
| 1139 | case TextureType::_2DMultisample: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 1140 | ASSERT(context->getClientVersion() < Version(3, 1) && |
| 1141 | !context->getExtensions().textureMultisample); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1142 | context->validationError(GL_INVALID_ENUM, kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1143 | break; |
| 1144 | |
| 1145 | case TextureType::_2DMultisampleArray: |
| 1146 | ASSERT(!context->getExtensions().textureStorageMultisample2DArray); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1147 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1148 | break; |
| 1149 | |
| 1150 | case TextureType::External: |
| 1151 | ASSERT(!context->getExtensions().eglImageExternal && |
| 1152 | !context->getExtensions().eglStreamConsumerExternal); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1153 | context->validationError(GL_INVALID_ENUM, "External texture extension not enabled"); |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1154 | break; |
| 1155 | |
| 1156 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1157 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1158 | } |
| 1159 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1160 | } // anonymous namespace |
| 1161 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1162 | bool ValidateES2TexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1163 | TextureTarget target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1164 | GLint level, |
| 1165 | GLenum internalformat, |
| 1166 | bool isCompressed, |
| 1167 | bool isSubImage, |
| 1168 | GLint xoffset, |
| 1169 | GLint yoffset, |
| 1170 | GLsizei width, |
| 1171 | GLsizei height, |
| 1172 | GLint border, |
| 1173 | GLenum format, |
| 1174 | GLenum type, |
| 1175 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1176 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1177 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1178 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1179 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1180 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1181 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1182 | } |
| 1183 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1184 | TextureType texType = TextureTargetToType(target); |
| 1185 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1186 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1187 | // Error already handled. |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1188 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1189 | } |
| 1190 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1191 | if (!ValidMipLevel(context, texType, level)) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1192 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1193 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1194 | return false; |
| 1195 | } |
| 1196 | |
| 1197 | if (xoffset < 0 || std::numeric_limits<GLsizei>::max() - xoffset < width || |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1198 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1199 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1200 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1201 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1202 | } |
| 1203 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1204 | // From GL_CHROMIUM_color_buffer_float_rgb[a]: |
| 1205 | // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for |
| 1206 | // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the |
| 1207 | // internalformat parameter and format parameter of TexImage2D must match is lifted for this |
| 1208 | // case. |
| 1209 | bool nonEqualFormatsAllowed = |
| 1210 | (internalformat == GL_RGB32F && context->getExtensions().colorBufferFloatRGB) || |
| 1211 | (internalformat == GL_RGBA32F && context->getExtensions().colorBufferFloatRGBA); |
| 1212 | |
| 1213 | if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1214 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1215 | context->validationError(GL_INVALID_OPERATION, kInvalidFormatCombination); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1216 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1219 | const gl::Caps &caps = context->getCaps(); |
| 1220 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1221 | switch (texType) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1222 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1223 | case TextureType::_2D: |
| 1224 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 1225 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 1226 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1227 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1228 | return false; |
| 1229 | } |
| 1230 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1231 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1232 | case TextureType::Rectangle: |
| 1233 | ASSERT(level == 0); |
| 1234 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1235 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1236 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1237 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1238 | return false; |
| 1239 | } |
| 1240 | if (isCompressed) |
| 1241 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1242 | context->validationError(GL_INVALID_ENUM, |
| 1243 | "Rectangle texture cannot have a compressed format."); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1244 | return false; |
| 1245 | } |
| 1246 | break; |
| 1247 | |
| 1248 | case TextureType::CubeMap: |
| 1249 | if (!isSubImage && width != height) |
| 1250 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1251 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1252 | return false; |
| 1253 | } |
| 1254 | |
| 1255 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 1256 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 1257 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1258 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1259 | return false; |
| 1260 | } |
| 1261 | break; |
| 1262 | |
| 1263 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1264 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1265 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1266 | } |
| 1267 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1268 | gl::Texture *texture = context->getTargetTexture(texType); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1269 | if (!texture) |
| 1270 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1271 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1272 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1275 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1276 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1277 | const InternalFormat &textureInternalFormat = *texture->getFormat(target, level).info; |
| 1278 | if (textureInternalFormat.internalFormat == GL_NONE) |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1279 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1280 | context->validationError(GL_INVALID_OPERATION, "Texture level does not exist."); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1281 | return false; |
| 1282 | } |
| 1283 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1284 | if (format != GL_NONE) |
| 1285 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1286 | if (GetInternalFormatInfo(format, type).sizedInternalFormat != |
| 1287 | textureInternalFormat.sizedInternalFormat) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1288 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1289 | context->validationError(GL_INVALID_OPERATION, kTypeMismatch); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1290 | return false; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1295 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 1296 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1297 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1298 | return false; |
| 1299 | } |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1300 | |
| 1301 | if (width > 0 && height > 0 && pixels == nullptr && |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1302 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack) == nullptr) |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1303 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1304 | context->validationError(GL_INVALID_VALUE, kPixelDataNull); |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1305 | return false; |
| 1306 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1307 | } |
| 1308 | else |
| 1309 | { |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1310 | if (texture->getImmutableFormat()) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1311 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1312 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1313 | return false; |
| 1314 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | // Verify zero border |
| 1318 | if (border != 0) |
| 1319 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1320 | context->validationError(GL_INVALID_VALUE, kInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1321 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1322 | } |
| 1323 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1324 | if (isCompressed) |
| 1325 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1326 | GLenum actualInternalFormat = |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1327 | isSubImage ? texture->getFormat(target, level).info->sizedInternalFormat |
| 1328 | : internalformat; |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1329 | |
| 1330 | const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(actualInternalFormat); |
| 1331 | |
| 1332 | if (!internalFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1333 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1334 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1335 | return false; |
| 1336 | } |
| 1337 | |
| 1338 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), |
| 1339 | context->getExtensions())) |
| 1340 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1341 | context->validationError(GL_INVALID_ENUM, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1342 | return false; |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1343 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1344 | |
| 1345 | if (isSubImage) |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 1346 | { |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1347 | // From the OES_compressed_ETC1_RGB8_texture spec: |
| 1348 | // INVALID_OPERATION is generated by CompressedTexSubImage2D, TexSubImage2D, or |
| 1349 | // CopyTexSubImage2D if the texture image <level> bound to <target> has internal format |
| 1350 | // ETC1_RGB8_OES. |
| 1351 | if (actualInternalFormat == GL_ETC1_RGB8_OES) |
| 1352 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1353 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | e88e454 | 2018-05-03 15:05:57 -0400 | [diff] [blame] | 1354 | return false; |
| 1355 | } |
| 1356 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1357 | if (!ValidCompressedSubImageSize(context, actualInternalFormat, xoffset, yoffset, width, |
| 1358 | height, texture->getWidth(target, level), |
| 1359 | texture->getHeight(target, level))) |
| 1360 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1361 | context->validationError(GL_INVALID_OPERATION, |
| 1362 | "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1363 | return false; |
| 1364 | } |
| 1365 | |
| 1366 | if (format != actualInternalFormat) |
| 1367 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1368 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1369 | return false; |
| 1370 | } |
| 1371 | } |
| 1372 | else |
| 1373 | { |
| 1374 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 1375 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1376 | context->validationError(GL_INVALID_OPERATION, |
| 1377 | "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1378 | return false; |
| 1379 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | else |
| 1383 | { |
| 1384 | // validate <type> by itself (used as secondary key below) |
| 1385 | switch (type) |
| 1386 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1387 | case GL_UNSIGNED_BYTE: |
| 1388 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1389 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1390 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1391 | case GL_UNSIGNED_SHORT: |
| 1392 | case GL_UNSIGNED_INT: |
| 1393 | case GL_UNSIGNED_INT_24_8_OES: |
| 1394 | case GL_HALF_FLOAT_OES: |
| 1395 | case GL_FLOAT: |
| 1396 | break; |
| 1397 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1398 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1399 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | // validate <format> + <type> combinations |
| 1403 | // - invalid <format> -> sets INVALID_ENUM |
| 1404 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 1405 | switch (format) |
| 1406 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1407 | case GL_ALPHA: |
| 1408 | case GL_LUMINANCE: |
| 1409 | case GL_LUMINANCE_ALPHA: |
| 1410 | switch (type) |
| 1411 | { |
| 1412 | case GL_UNSIGNED_BYTE: |
| 1413 | case GL_FLOAT: |
| 1414 | case GL_HALF_FLOAT_OES: |
| 1415 | break; |
| 1416 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1417 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1418 | return false; |
| 1419 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1420 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1421 | case GL_RED: |
| 1422 | case GL_RG: |
| 1423 | if (!context->getExtensions().textureRG) |
| 1424 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1425 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1426 | return false; |
| 1427 | } |
| 1428 | switch (type) |
| 1429 | { |
| 1430 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1431 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1432 | case GL_FLOAT: |
| 1433 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1434 | if (!context->getExtensions().textureFloat) |
| 1435 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1436 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1437 | return false; |
| 1438 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1439 | break; |
| 1440 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1441 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1442 | return false; |
| 1443 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1444 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1445 | case GL_RGB: |
| 1446 | switch (type) |
| 1447 | { |
| 1448 | case GL_UNSIGNED_BYTE: |
| 1449 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1450 | case GL_FLOAT: |
| 1451 | case GL_HALF_FLOAT_OES: |
| 1452 | break; |
| 1453 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1454 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1455 | return false; |
| 1456 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1457 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1458 | case GL_RGBA: |
| 1459 | switch (type) |
| 1460 | { |
| 1461 | case GL_UNSIGNED_BYTE: |
| 1462 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1463 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1464 | case GL_FLOAT: |
| 1465 | case GL_HALF_FLOAT_OES: |
| 1466 | break; |
| 1467 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1468 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1469 | return false; |
| 1470 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1471 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1472 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1473 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1474 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1475 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1476 | return false; |
| 1477 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1478 | switch (type) |
| 1479 | { |
| 1480 | case GL_UNSIGNED_BYTE: |
| 1481 | break; |
| 1482 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1483 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1484 | return false; |
| 1485 | } |
| 1486 | break; |
| 1487 | case GL_SRGB_EXT: |
| 1488 | case GL_SRGB_ALPHA_EXT: |
| 1489 | if (!context->getExtensions().sRGB) |
| 1490 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1491 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1492 | return false; |
| 1493 | } |
| 1494 | switch (type) |
| 1495 | { |
| 1496 | case GL_UNSIGNED_BYTE: |
| 1497 | break; |
| 1498 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1499 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1500 | return false; |
| 1501 | } |
| 1502 | break; |
| 1503 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1504 | // handled below |
| 1505 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1506 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1507 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1508 | break; |
| 1509 | case GL_DEPTH_COMPONENT: |
| 1510 | switch (type) |
| 1511 | { |
| 1512 | case GL_UNSIGNED_SHORT: |
| 1513 | case GL_UNSIGNED_INT: |
| 1514 | break; |
| 1515 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1516 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1517 | return false; |
| 1518 | } |
| 1519 | break; |
| 1520 | case GL_DEPTH_STENCIL_OES: |
| 1521 | switch (type) |
| 1522 | { |
| 1523 | case GL_UNSIGNED_INT_24_8_OES: |
| 1524 | break; |
| 1525 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1526 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1527 | return false; |
| 1528 | } |
| 1529 | break; |
| 1530 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1531 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1532 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | switch (format) |
| 1536 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1537 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1538 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1539 | if (context->getExtensions().textureCompressionDXT1) |
| 1540 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1541 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1542 | return false; |
| 1543 | } |
| 1544 | else |
| 1545 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1546 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1547 | return false; |
| 1548 | } |
| 1549 | break; |
| 1550 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1551 | if (context->getExtensions().textureCompressionDXT3) |
| 1552 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1553 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1554 | return false; |
| 1555 | } |
| 1556 | else |
| 1557 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1558 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1559 | return false; |
| 1560 | } |
| 1561 | break; |
| 1562 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1563 | if (context->getExtensions().textureCompressionDXT5) |
| 1564 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1565 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1566 | return false; |
| 1567 | } |
| 1568 | else |
| 1569 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1570 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1571 | return false; |
| 1572 | } |
| 1573 | break; |
| 1574 | case GL_ETC1_RGB8_OES: |
| 1575 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1576 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1577 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1578 | return false; |
| 1579 | } |
| 1580 | else |
| 1581 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1582 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1583 | return false; |
| 1584 | } |
| 1585 | break; |
| 1586 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1587 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1588 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1589 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1590 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1591 | if (context->getExtensions().lossyETCDecode) |
| 1592 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1593 | context->validationError(GL_INVALID_OPERATION, |
| 1594 | "ETC lossy decode formats can't work with this type."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1595 | return false; |
| 1596 | } |
| 1597 | else |
| 1598 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1599 | context->validationError(GL_INVALID_ENUM, |
| 1600 | "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1601 | return false; |
| 1602 | } |
| 1603 | break; |
| 1604 | case GL_DEPTH_COMPONENT: |
| 1605 | case GL_DEPTH_STENCIL_OES: |
| 1606 | if (!context->getExtensions().depthTextures) |
| 1607 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1608 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1609 | return false; |
| 1610 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1611 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1612 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1613 | context->validationError(GL_INVALID_OPERATION, kMismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1614 | return false; |
| 1615 | } |
| 1616 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1617 | // but ANGLE_depth_texture does not |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1618 | if (pixels != nullptr) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1619 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1620 | context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull); |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1621 | return false; |
| 1622 | } |
| 1623 | if (level != 0) |
| 1624 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1625 | context->validationError(GL_INVALID_OPERATION, kLevelNotZero); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1626 | return false; |
| 1627 | } |
| 1628 | break; |
| 1629 | default: |
| 1630 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1631 | } |
| 1632 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1633 | if (!isSubImage) |
| 1634 | { |
| 1635 | switch (internalformat) |
| 1636 | { |
| 1637 | case GL_RGBA32F: |
| 1638 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1639 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1640 | context->validationError(GL_INVALID_ENUM, |
| 1641 | "Sized GL_RGBA32F internal format requires " |
| 1642 | "GL_CHROMIUM_color_buffer_float_rgba"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1643 | return false; |
| 1644 | } |
| 1645 | if (type != GL_FLOAT) |
| 1646 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1647 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1648 | return false; |
| 1649 | } |
| 1650 | if (format != GL_RGBA) |
| 1651 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1652 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1653 | return false; |
| 1654 | } |
| 1655 | break; |
| 1656 | |
| 1657 | case GL_RGB32F: |
| 1658 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1659 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1660 | context->validationError(GL_INVALID_ENUM, |
| 1661 | "Sized GL_RGB32F internal format requires " |
| 1662 | "GL_CHROMIUM_color_buffer_float_rgb"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1663 | return false; |
| 1664 | } |
| 1665 | if (type != GL_FLOAT) |
| 1666 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1667 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1668 | return false; |
| 1669 | } |
| 1670 | if (format != GL_RGB) |
| 1671 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1672 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1673 | return false; |
| 1674 | } |
| 1675 | break; |
| 1676 | |
| 1677 | default: |
| 1678 | break; |
| 1679 | } |
| 1680 | } |
| 1681 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1682 | if (type == GL_FLOAT) |
| 1683 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1684 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1685 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1686 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1687 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1688 | } |
| 1689 | } |
| 1690 | else if (type == GL_HALF_FLOAT_OES) |
| 1691 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1692 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1693 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1694 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1695 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 1700 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1701 | if (!ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1702 | imageSize)) |
| 1703 | { |
| 1704 | return false; |
| 1705 | } |
| 1706 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1707 | return true; |
| 1708 | } |
| 1709 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1710 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1711 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1712 | GLsizei levels, |
| 1713 | GLenum internalformat, |
| 1714 | GLsizei width, |
| 1715 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1716 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1717 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1718 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1719 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1720 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1721 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | if (width < 1 || height < 1 || levels < 1) |
| 1725 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1726 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1727 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1728 | } |
| 1729 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1730 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1731 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1732 | context->validationError(GL_INVALID_VALUE, kCubemapFacesEqualDimensions); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1733 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1737 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1738 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1739 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1742 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1743 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1744 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1745 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1746 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1747 | } |
| 1748 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1749 | const gl::Caps &caps = context->getCaps(); |
| 1750 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1751 | switch (target) |
| 1752 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1753 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1754 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1755 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1756 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1757 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1758 | return false; |
| 1759 | } |
| 1760 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1761 | case TextureType::Rectangle: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1762 | if (levels != 1) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1763 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1764 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1765 | return false; |
| 1766 | } |
| 1767 | |
| 1768 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1769 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1770 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1771 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1772 | return false; |
| 1773 | } |
| 1774 | if (formatInfo.compressed) |
| 1775 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1776 | context->validationError(GL_INVALID_ENUM, kRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1777 | return false; |
| 1778 | } |
| 1779 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1780 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1781 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1782 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1783 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1784 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1785 | return false; |
| 1786 | } |
| 1787 | break; |
| 1788 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1789 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1790 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1791 | } |
| 1792 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1793 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1794 | { |
| 1795 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1796 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1797 | context->validationError(GL_INVALID_OPERATION, kDimensionsMustBePow2); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1798 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | switch (internalformat) |
| 1803 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1804 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1805 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1806 | if (!context->getExtensions().textureCompressionDXT1) |
| 1807 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1808 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1809 | return false; |
| 1810 | } |
| 1811 | break; |
| 1812 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1813 | if (!context->getExtensions().textureCompressionDXT3) |
| 1814 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1815 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1816 | return false; |
| 1817 | } |
| 1818 | break; |
| 1819 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1820 | if (!context->getExtensions().textureCompressionDXT5) |
| 1821 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1822 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1823 | return false; |
| 1824 | } |
| 1825 | break; |
| 1826 | case GL_ETC1_RGB8_OES: |
| 1827 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1828 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1829 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1830 | return false; |
| 1831 | } |
| 1832 | break; |
| 1833 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1834 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1835 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1836 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1837 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1838 | if (!context->getExtensions().lossyETCDecode) |
| 1839 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1840 | context->validationError(GL_INVALID_ENUM, |
| 1841 | "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1842 | return false; |
| 1843 | } |
| 1844 | break; |
| 1845 | case GL_RGBA32F_EXT: |
| 1846 | case GL_RGB32F_EXT: |
| 1847 | case GL_ALPHA32F_EXT: |
| 1848 | case GL_LUMINANCE32F_EXT: |
| 1849 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1850 | if (!context->getExtensions().textureFloat) |
| 1851 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1852 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1853 | return false; |
| 1854 | } |
| 1855 | break; |
| 1856 | case GL_RGBA16F_EXT: |
| 1857 | case GL_RGB16F_EXT: |
| 1858 | case GL_ALPHA16F_EXT: |
| 1859 | case GL_LUMINANCE16F_EXT: |
| 1860 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1861 | if (!context->getExtensions().textureHalfFloat) |
| 1862 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1863 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1864 | return false; |
| 1865 | } |
| 1866 | break; |
| 1867 | case GL_R8_EXT: |
| 1868 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1869 | if (!context->getExtensions().textureRG) |
| 1870 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1871 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1872 | return false; |
| 1873 | } |
| 1874 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1875 | case GL_R16F_EXT: |
| 1876 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1877 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1878 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1879 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1880 | return false; |
| 1881 | } |
| 1882 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1883 | case GL_R32F_EXT: |
| 1884 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1885 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1886 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1887 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1888 | return false; |
| 1889 | } |
| 1890 | break; |
| 1891 | case GL_DEPTH_COMPONENT16: |
| 1892 | case GL_DEPTH_COMPONENT32_OES: |
| 1893 | case GL_DEPTH24_STENCIL8_OES: |
| 1894 | if (!context->getExtensions().depthTextures) |
| 1895 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1896 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1897 | return false; |
| 1898 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1899 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1900 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1901 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1902 | return false; |
| 1903 | } |
| 1904 | // ANGLE_depth_texture only supports 1-level textures |
| 1905 | if (levels != 1) |
| 1906 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1907 | context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1908 | return false; |
| 1909 | } |
| 1910 | break; |
| 1911 | default: |
| 1912 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1913 | } |
| 1914 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1915 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1916 | if (!texture || texture->id() == 0) |
| 1917 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1918 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1919 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1920 | } |
| 1921 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1922 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1923 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1924 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1925 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | return true; |
| 1929 | } |
| 1930 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1931 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 1932 | GLenum target, |
| 1933 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1934 | const GLenum *attachments) |
| 1935 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1936 | if (!context->getExtensions().discardFramebuffer) |
| 1937 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1938 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1939 | return false; |
| 1940 | } |
| 1941 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1942 | bool defaultFramebuffer = false; |
| 1943 | |
| 1944 | switch (target) |
| 1945 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1946 | case GL_FRAMEBUFFER: |
| 1947 | defaultFramebuffer = |
| 1948 | (context->getGLState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
| 1949 | break; |
| 1950 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1951 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1952 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1955 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1956 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1959 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 1960 | { |
| 1961 | if (!context->getExtensions().vertexArrayObject) |
| 1962 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1963 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1964 | return false; |
| 1965 | } |
| 1966 | |
| 1967 | return ValidateBindVertexArrayBase(context, array); |
| 1968 | } |
| 1969 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1970 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1971 | { |
| 1972 | if (!context->getExtensions().vertexArrayObject) |
| 1973 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1974 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1975 | return false; |
| 1976 | } |
| 1977 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1978 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1981 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1982 | { |
| 1983 | if (!context->getExtensions().vertexArrayObject) |
| 1984 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1985 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1986 | return false; |
| 1987 | } |
| 1988 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1989 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1992 | bool ValidateIsVertexArrayOES(Context *context, GLuint array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1993 | { |
| 1994 | if (!context->getExtensions().vertexArrayObject) |
| 1995 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1996 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1997 | return false; |
| 1998 | } |
| 1999 | |
| 2000 | return true; |
| 2001 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2002 | |
| 2003 | bool ValidateProgramBinaryOES(Context *context, |
| 2004 | GLuint program, |
| 2005 | GLenum binaryFormat, |
| 2006 | const void *binary, |
| 2007 | GLint length) |
| 2008 | { |
| 2009 | if (!context->getExtensions().getProgramBinary) |
| 2010 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2011 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2012 | return false; |
| 2013 | } |
| 2014 | |
| 2015 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 2016 | } |
| 2017 | |
| 2018 | bool ValidateGetProgramBinaryOES(Context *context, |
| 2019 | GLuint program, |
| 2020 | GLsizei bufSize, |
| 2021 | GLsizei *length, |
| 2022 | GLenum *binaryFormat, |
| 2023 | void *binary) |
| 2024 | { |
| 2025 | if (!context->getExtensions().getProgramBinary) |
| 2026 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2027 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2028 | return false; |
| 2029 | } |
| 2030 | |
| 2031 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 2032 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2033 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2034 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 2035 | { |
| 2036 | switch (source) |
| 2037 | { |
| 2038 | case GL_DEBUG_SOURCE_API: |
| 2039 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 2040 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 2041 | case GL_DEBUG_SOURCE_OTHER: |
| 2042 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 2043 | return !mustBeThirdPartyOrApplication; |
| 2044 | |
| 2045 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 2046 | case GL_DEBUG_SOURCE_APPLICATION: |
| 2047 | return true; |
| 2048 | |
| 2049 | default: |
| 2050 | return false; |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | static bool ValidDebugType(GLenum type) |
| 2055 | { |
| 2056 | switch (type) |
| 2057 | { |
| 2058 | case GL_DEBUG_TYPE_ERROR: |
| 2059 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 2060 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 2061 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 2062 | case GL_DEBUG_TYPE_PORTABILITY: |
| 2063 | case GL_DEBUG_TYPE_OTHER: |
| 2064 | case GL_DEBUG_TYPE_MARKER: |
| 2065 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 2066 | case GL_DEBUG_TYPE_POP_GROUP: |
| 2067 | return true; |
| 2068 | |
| 2069 | default: |
| 2070 | return false; |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | static bool ValidDebugSeverity(GLenum severity) |
| 2075 | { |
| 2076 | switch (severity) |
| 2077 | { |
| 2078 | case GL_DEBUG_SEVERITY_HIGH: |
| 2079 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 2080 | case GL_DEBUG_SEVERITY_LOW: |
| 2081 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 2082 | return true; |
| 2083 | |
| 2084 | default: |
| 2085 | return false; |
| 2086 | } |
| 2087 | } |
| 2088 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2089 | bool ValidateDebugMessageControlKHR(Context *context, |
| 2090 | GLenum source, |
| 2091 | GLenum type, |
| 2092 | GLenum severity, |
| 2093 | GLsizei count, |
| 2094 | const GLuint *ids, |
| 2095 | GLboolean enabled) |
| 2096 | { |
| 2097 | if (!context->getExtensions().debug) |
| 2098 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2099 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2100 | return false; |
| 2101 | } |
| 2102 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2103 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 2104 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2105 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2106 | return false; |
| 2107 | } |
| 2108 | |
| 2109 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 2110 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2111 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2112 | return false; |
| 2113 | } |
| 2114 | |
| 2115 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 2116 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2117 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2118 | return false; |
| 2119 | } |
| 2120 | |
| 2121 | if (count > 0) |
| 2122 | { |
| 2123 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2124 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2125 | context->validationError( |
| 2126 | GL_INVALID_OPERATION, |
| 2127 | "If count is greater than zero, source and severity cannot be GL_DONT_CARE."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2128 | return false; |
| 2129 | } |
| 2130 | |
| 2131 | if (severity != GL_DONT_CARE) |
| 2132 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2133 | context->validationError( |
| 2134 | GL_INVALID_OPERATION, |
| 2135 | "If count is greater than zero, severity must be GL_DONT_CARE."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2136 | return false; |
| 2137 | } |
| 2138 | } |
| 2139 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2140 | return true; |
| 2141 | } |
| 2142 | |
| 2143 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2144 | GLenum source, |
| 2145 | GLenum type, |
| 2146 | GLuint id, |
| 2147 | GLenum severity, |
| 2148 | GLsizei length, |
| 2149 | const GLchar *buf) |
| 2150 | { |
| 2151 | if (!context->getExtensions().debug) |
| 2152 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2153 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2154 | return false; |
| 2155 | } |
| 2156 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2157 | if (!context->getGLState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2158 | { |
| 2159 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2160 | // not generate an error. |
| 2161 | return false; |
| 2162 | } |
| 2163 | |
| 2164 | if (!ValidDebugSeverity(severity)) |
| 2165 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2166 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2167 | return false; |
| 2168 | } |
| 2169 | |
| 2170 | if (!ValidDebugType(type)) |
| 2171 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2172 | context->validationError(GL_INVALID_ENUM, kInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2173 | return false; |
| 2174 | } |
| 2175 | |
| 2176 | if (!ValidDebugSource(source, true)) |
| 2177 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2178 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2179 | return false; |
| 2180 | } |
| 2181 | |
| 2182 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2183 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2184 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2185 | context->validationError(GL_INVALID_VALUE, |
| 2186 | "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2187 | return false; |
| 2188 | } |
| 2189 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2190 | return true; |
| 2191 | } |
| 2192 | |
| 2193 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2194 | GLDEBUGPROCKHR callback, |
| 2195 | const void *userParam) |
| 2196 | { |
| 2197 | if (!context->getExtensions().debug) |
| 2198 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2199 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2200 | return false; |
| 2201 | } |
| 2202 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2203 | return true; |
| 2204 | } |
| 2205 | |
| 2206 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2207 | GLuint count, |
| 2208 | GLsizei bufSize, |
| 2209 | GLenum *sources, |
| 2210 | GLenum *types, |
| 2211 | GLuint *ids, |
| 2212 | GLenum *severities, |
| 2213 | GLsizei *lengths, |
| 2214 | GLchar *messageLog) |
| 2215 | { |
| 2216 | if (!context->getExtensions().debug) |
| 2217 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2218 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2219 | return false; |
| 2220 | } |
| 2221 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2222 | if (bufSize < 0 && messageLog != nullptr) |
| 2223 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2224 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2225 | return false; |
| 2226 | } |
| 2227 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2228 | return true; |
| 2229 | } |
| 2230 | |
| 2231 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2232 | GLenum source, |
| 2233 | GLuint id, |
| 2234 | GLsizei length, |
| 2235 | const GLchar *message) |
| 2236 | { |
| 2237 | if (!context->getExtensions().debug) |
| 2238 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2239 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2240 | return false; |
| 2241 | } |
| 2242 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2243 | if (!ValidDebugSource(source, true)) |
| 2244 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2245 | context->validationError(GL_INVALID_ENUM, kInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2246 | return false; |
| 2247 | } |
| 2248 | |
| 2249 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2250 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2251 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2252 | context->validationError(GL_INVALID_VALUE, |
| 2253 | "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2254 | return false; |
| 2255 | } |
| 2256 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2257 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2258 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2259 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2260 | context->validationError( |
| 2261 | GL_STACK_OVERFLOW, |
| 2262 | "Cannot push more than GL_MAX_DEBUG_GROUP_STACK_DEPTH debug groups."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2263 | return false; |
| 2264 | } |
| 2265 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2266 | return true; |
| 2267 | } |
| 2268 | |
| 2269 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2270 | { |
| 2271 | if (!context->getExtensions().debug) |
| 2272 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2273 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2274 | return false; |
| 2275 | } |
| 2276 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2277 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2278 | if (currentStackSize <= 1) |
| 2279 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2280 | context->validationError(GL_STACK_UNDERFLOW, "Cannot pop the default debug group."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2281 | return false; |
| 2282 | } |
| 2283 | |
| 2284 | return true; |
| 2285 | } |
| 2286 | |
| 2287 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2288 | { |
| 2289 | switch (identifier) |
| 2290 | { |
| 2291 | case GL_BUFFER: |
| 2292 | if (context->getBuffer(name) == nullptr) |
| 2293 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2294 | context->validationError(GL_INVALID_VALUE, "name is not a valid buffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2295 | return false; |
| 2296 | } |
| 2297 | return true; |
| 2298 | |
| 2299 | case GL_SHADER: |
| 2300 | if (context->getShader(name) == nullptr) |
| 2301 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2302 | context->validationError(GL_INVALID_VALUE, "name is not a valid shader."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2303 | return false; |
| 2304 | } |
| 2305 | return true; |
| 2306 | |
| 2307 | case GL_PROGRAM: |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2308 | if (context->getProgramNoResolveLink(name) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2309 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2310 | context->validationError(GL_INVALID_VALUE, "name is not a valid program."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2311 | return false; |
| 2312 | } |
| 2313 | return true; |
| 2314 | |
| 2315 | case GL_VERTEX_ARRAY: |
| 2316 | if (context->getVertexArray(name) == nullptr) |
| 2317 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2318 | context->validationError(GL_INVALID_VALUE, "name is not a valid vertex array."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2319 | return false; |
| 2320 | } |
| 2321 | return true; |
| 2322 | |
| 2323 | case GL_QUERY: |
| 2324 | if (context->getQuery(name) == nullptr) |
| 2325 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2326 | context->validationError(GL_INVALID_VALUE, "name is not a valid query."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2327 | return false; |
| 2328 | } |
| 2329 | return true; |
| 2330 | |
| 2331 | case GL_TRANSFORM_FEEDBACK: |
| 2332 | if (context->getTransformFeedback(name) == nullptr) |
| 2333 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2334 | context->validationError(GL_INVALID_VALUE, |
| 2335 | "name is not a valid transform feedback."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2336 | return false; |
| 2337 | } |
| 2338 | return true; |
| 2339 | |
| 2340 | case GL_SAMPLER: |
| 2341 | if (context->getSampler(name) == nullptr) |
| 2342 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2343 | context->validationError(GL_INVALID_VALUE, "name is not a valid sampler."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2344 | return false; |
| 2345 | } |
| 2346 | return true; |
| 2347 | |
| 2348 | case GL_TEXTURE: |
| 2349 | if (context->getTexture(name) == nullptr) |
| 2350 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2351 | context->validationError(GL_INVALID_VALUE, "name is not a valid texture."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2352 | return false; |
| 2353 | } |
| 2354 | return true; |
| 2355 | |
| 2356 | case GL_RENDERBUFFER: |
| 2357 | if (context->getRenderbuffer(name) == nullptr) |
| 2358 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2359 | context->validationError(GL_INVALID_VALUE, "name is not a valid renderbuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2360 | return false; |
| 2361 | } |
| 2362 | return true; |
| 2363 | |
| 2364 | case GL_FRAMEBUFFER: |
| 2365 | if (context->getFramebuffer(name) == nullptr) |
| 2366 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2367 | context->validationError(GL_INVALID_VALUE, "name is not a valid framebuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2368 | return false; |
| 2369 | } |
| 2370 | return true; |
| 2371 | |
| 2372 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2373 | context->validationError(GL_INVALID_ENUM, "Invalid identifier."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2374 | return false; |
| 2375 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2376 | } |
| 2377 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2378 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2379 | { |
| 2380 | size_t labelLength = 0; |
| 2381 | |
| 2382 | if (length < 0) |
| 2383 | { |
| 2384 | if (label != nullptr) |
| 2385 | { |
| 2386 | labelLength = strlen(label); |
| 2387 | } |
| 2388 | } |
| 2389 | else |
| 2390 | { |
| 2391 | labelLength = static_cast<size_t>(length); |
| 2392 | } |
| 2393 | |
| 2394 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2395 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2396 | context->validationError(GL_INVALID_VALUE, |
| 2397 | "Label length is larger than GL_MAX_LABEL_LENGTH."); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2398 | return false; |
| 2399 | } |
| 2400 | |
| 2401 | return true; |
| 2402 | } |
| 2403 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2404 | bool ValidateObjectLabelKHR(Context *context, |
| 2405 | GLenum identifier, |
| 2406 | GLuint name, |
| 2407 | GLsizei length, |
| 2408 | const GLchar *label) |
| 2409 | { |
| 2410 | if (!context->getExtensions().debug) |
| 2411 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2412 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2413 | return false; |
| 2414 | } |
| 2415 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2416 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2417 | { |
| 2418 | return false; |
| 2419 | } |
| 2420 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2421 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2422 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2423 | return false; |
| 2424 | } |
| 2425 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2426 | return true; |
| 2427 | } |
| 2428 | |
| 2429 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2430 | GLenum identifier, |
| 2431 | GLuint name, |
| 2432 | GLsizei bufSize, |
| 2433 | GLsizei *length, |
| 2434 | GLchar *label) |
| 2435 | { |
| 2436 | if (!context->getExtensions().debug) |
| 2437 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2438 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2439 | return false; |
| 2440 | } |
| 2441 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2442 | if (bufSize < 0) |
| 2443 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2444 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2445 | return false; |
| 2446 | } |
| 2447 | |
| 2448 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2449 | { |
| 2450 | return false; |
| 2451 | } |
| 2452 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2453 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2457 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2458 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2459 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2460 | context->validationError(GL_INVALID_VALUE, "name is not a valid sync."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2461 | return false; |
| 2462 | } |
| 2463 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2464 | return true; |
| 2465 | } |
| 2466 | |
| 2467 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2468 | const void *ptr, |
| 2469 | GLsizei length, |
| 2470 | const GLchar *label) |
| 2471 | { |
| 2472 | if (!context->getExtensions().debug) |
| 2473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2474 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2475 | return false; |
| 2476 | } |
| 2477 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2478 | if (!ValidateObjectPtrName(context, ptr)) |
| 2479 | { |
| 2480 | return false; |
| 2481 | } |
| 2482 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2483 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2484 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2485 | return false; |
| 2486 | } |
| 2487 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2488 | return true; |
| 2489 | } |
| 2490 | |
| 2491 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2492 | const void *ptr, |
| 2493 | GLsizei bufSize, |
| 2494 | GLsizei *length, |
| 2495 | GLchar *label) |
| 2496 | { |
| 2497 | if (!context->getExtensions().debug) |
| 2498 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2499 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2500 | return false; |
| 2501 | } |
| 2502 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2503 | if (bufSize < 0) |
| 2504 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2505 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2506 | return false; |
| 2507 | } |
| 2508 | |
| 2509 | if (!ValidateObjectPtrName(context, ptr)) |
| 2510 | { |
| 2511 | return false; |
| 2512 | } |
| 2513 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2514 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2518 | { |
| 2519 | if (!context->getExtensions().debug) |
| 2520 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2521 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2522 | return false; |
| 2523 | } |
| 2524 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2525 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2526 | switch (pname) |
| 2527 | { |
| 2528 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2529 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2530 | break; |
| 2531 | |
| 2532 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2533 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2534 | return false; |
| 2535 | } |
| 2536 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2537 | return true; |
| 2538 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2539 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2540 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2541 | GLenum pname, |
| 2542 | GLsizei bufSize, |
| 2543 | GLsizei *length, |
| 2544 | void **params) |
| 2545 | { |
| 2546 | UNIMPLEMENTED(); |
| 2547 | return false; |
| 2548 | } |
| 2549 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2550 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2551 | GLint srcX0, |
| 2552 | GLint srcY0, |
| 2553 | GLint srcX1, |
| 2554 | GLint srcY1, |
| 2555 | GLint dstX0, |
| 2556 | GLint dstY0, |
| 2557 | GLint dstX1, |
| 2558 | GLint dstY1, |
| 2559 | GLbitfield mask, |
| 2560 | GLenum filter) |
| 2561 | { |
| 2562 | if (!context->getExtensions().framebufferBlit) |
| 2563 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2564 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2565 | return false; |
| 2566 | } |
| 2567 | |
| 2568 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2569 | { |
| 2570 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2571 | context->validationError(GL_INVALID_OPERATION, kBlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2572 | return false; |
| 2573 | } |
| 2574 | |
| 2575 | if (filter == GL_LINEAR) |
| 2576 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2577 | context->validationError(GL_INVALID_ENUM, kBlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2578 | return false; |
| 2579 | } |
| 2580 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2581 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2582 | Framebuffer *drawFramebuffer = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2583 | |
| 2584 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2585 | { |
| 2586 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 2587 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 2588 | |
| 2589 | if (readColorAttachment && drawColorAttachment) |
| 2590 | { |
| 2591 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2592 | readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2593 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2594 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2595 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2596 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2597 | kBlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2598 | return false; |
| 2599 | } |
| 2600 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2601 | for (size_t drawbufferIdx = 0; |
| 2602 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2603 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2604 | const FramebufferAttachment *attachment = |
| 2605 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2606 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2607 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2608 | if (!(attachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2609 | attachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2610 | attachment->type() != GL_RENDERBUFFER && |
| 2611 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2612 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2613 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2614 | kBlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2615 | return false; |
| 2616 | } |
| 2617 | |
| 2618 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2619 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2620 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2621 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2622 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2623 | kBlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2624 | return false; |
| 2625 | } |
| 2626 | } |
| 2627 | } |
| 2628 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2629 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2630 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2631 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2632 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2633 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2634 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2635 | kBlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2636 | return false; |
| 2637 | } |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2642 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2643 | for (size_t i = 0; i < 2; i++) |
| 2644 | { |
| 2645 | if (mask & masks[i]) |
| 2646 | { |
| 2647 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2648 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2649 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2650 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2651 | |
| 2652 | if (readBuffer && drawBuffer) |
| 2653 | { |
| 2654 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2655 | dstX0, dstY0, dstX1, dstY1)) |
| 2656 | { |
| 2657 | // only whole-buffer copies are permitted |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2658 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2659 | kBlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2660 | return false; |
| 2661 | } |
| 2662 | |
| 2663 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2664 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2665 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2666 | kBlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2667 | return false; |
| 2668 | } |
| 2669 | } |
| 2670 | } |
| 2671 | } |
| 2672 | |
| 2673 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2674 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2675 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2676 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2677 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2678 | { |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 2679 | Framebuffer *fbo = context->getGLState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2680 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2681 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2682 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2683 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2684 | return false; |
| 2685 | } |
| 2686 | |
| 2687 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2688 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2689 | context->validationError(GL_INVALID_VALUE, kInvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2690 | return false; |
| 2691 | } |
| 2692 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2693 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2694 | { |
| 2695 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2696 | GL_SIGNED_NORMALIZED}; |
| 2697 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2698 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2699 | drawBufferIdx++) |
| 2700 | { |
| 2701 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2702 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2703 | { |
| 2704 | return false; |
| 2705 | } |
| 2706 | } |
| 2707 | } |
| 2708 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2709 | if (extensions.multiview && extensions.disjointTimerQuery) |
| 2710 | { |
| 2711 | const State &state = context->getGLState(); |
| 2712 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2713 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2714 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2715 | context->validationError(GL_INVALID_OPERATION, |
| 2716 | "There is an active query for target " |
| 2717 | "GL_TIME_ELAPSED_EXT when the number of " |
| 2718 | "views in the active draw framebuffer is " |
| 2719 | "greater than 1."); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2720 | return false; |
| 2721 | } |
| 2722 | } |
| 2723 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2724 | return true; |
| 2725 | } |
| 2726 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2727 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2728 | { |
| 2729 | if (!context->getExtensions().drawBuffers) |
| 2730 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2731 | context->validationError(GL_INVALID_OPERATION, "Extension not supported."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2732 | return false; |
| 2733 | } |
| 2734 | |
| 2735 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2736 | } |
| 2737 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2738 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2739 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2740 | GLint level, |
| 2741 | GLint internalformat, |
| 2742 | GLsizei width, |
| 2743 | GLsizei height, |
| 2744 | GLint border, |
| 2745 | GLenum format, |
| 2746 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2747 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2748 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2749 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2750 | { |
| 2751 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2752 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2753 | } |
| 2754 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2755 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2756 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2757 | 0, 0, width, height, 1, border, format, type, -1, |
| 2758 | pixels); |
| 2759 | } |
| 2760 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2761 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2762 | TextureTarget target, |
| 2763 | GLint level, |
| 2764 | GLint internalformat, |
| 2765 | GLsizei width, |
| 2766 | GLsizei height, |
| 2767 | GLint border, |
| 2768 | GLenum format, |
| 2769 | GLenum type, |
| 2770 | GLsizei bufSize, |
| 2771 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2772 | { |
| 2773 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2774 | { |
| 2775 | return false; |
| 2776 | } |
| 2777 | |
| 2778 | if (context->getClientMajorVersion() < 3) |
| 2779 | { |
| 2780 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2781 | 0, 0, width, height, border, format, type, bufSize, |
| 2782 | pixels); |
| 2783 | } |
| 2784 | |
| 2785 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2786 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2787 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2788 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2792 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2793 | GLint level, |
| 2794 | GLint xoffset, |
| 2795 | GLint yoffset, |
| 2796 | GLsizei width, |
| 2797 | GLsizei height, |
| 2798 | GLenum format, |
| 2799 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2800 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2801 | { |
| 2802 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2803 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2804 | { |
| 2805 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2806 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2807 | } |
| 2808 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2809 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2810 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2811 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2812 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2813 | } |
| 2814 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2815 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2816 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2817 | GLint level, |
| 2818 | GLint xoffset, |
| 2819 | GLint yoffset, |
| 2820 | GLsizei width, |
| 2821 | GLsizei height, |
| 2822 | GLenum format, |
| 2823 | GLenum type, |
| 2824 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2825 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2826 | { |
| 2827 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2828 | { |
| 2829 | return false; |
| 2830 | } |
| 2831 | |
| 2832 | if (context->getClientMajorVersion() < 3) |
| 2833 | { |
| 2834 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2835 | yoffset, width, height, 0, format, type, bufSize, |
| 2836 | pixels); |
| 2837 | } |
| 2838 | |
| 2839 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2840 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2841 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2842 | pixels); |
| 2843 | } |
| 2844 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2845 | bool ValidateCompressedTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2846 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2847 | GLint level, |
| 2848 | GLenum internalformat, |
| 2849 | GLsizei width, |
| 2850 | GLsizei height, |
| 2851 | GLint border, |
| 2852 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2853 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2854 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2855 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2856 | { |
| 2857 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2858 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2859 | { |
| 2860 | return false; |
| 2861 | } |
| 2862 | } |
| 2863 | else |
| 2864 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2865 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2866 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2867 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2868 | data)) |
| 2869 | { |
| 2870 | return false; |
| 2871 | } |
| 2872 | } |
| 2873 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2874 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2875 | |
| 2876 | GLuint blockSize = 0; |
| 2877 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2878 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2879 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2880 | return false; |
| 2881 | } |
| 2882 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2883 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2884 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2885 | context->validationError(GL_INVALID_VALUE, kCompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2886 | return false; |
| 2887 | } |
| 2888 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2889 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2890 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2891 | context->validationError(GL_INVALID_ENUM, |
| 2892 | "Rectangle texture cannot have a compressed format."); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2893 | return false; |
| 2894 | } |
| 2895 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2896 | return true; |
| 2897 | } |
| 2898 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2899 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2900 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2901 | GLint level, |
| 2902 | GLenum internalformat, |
| 2903 | GLsizei width, |
| 2904 | GLsizei height, |
| 2905 | GLint border, |
| 2906 | GLsizei imageSize, |
| 2907 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2908 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2909 | { |
| 2910 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2911 | { |
| 2912 | return false; |
| 2913 | } |
| 2914 | |
| 2915 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 2916 | border, imageSize, data); |
| 2917 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2918 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2919 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2920 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2921 | GLint level, |
| 2922 | GLint xoffset, |
| 2923 | GLint yoffset, |
| 2924 | GLsizei width, |
| 2925 | GLsizei height, |
| 2926 | GLenum format, |
| 2927 | GLsizei imageSize, |
| 2928 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2929 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2930 | { |
| 2931 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2932 | { |
| 2933 | return false; |
| 2934 | } |
| 2935 | |
| 2936 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 2937 | format, imageSize, data); |
| 2938 | } |
| 2939 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2940 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2941 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2942 | GLint level, |
| 2943 | GLint xoffset, |
| 2944 | GLint yoffset, |
| 2945 | GLsizei width, |
| 2946 | GLsizei height, |
| 2947 | GLenum format, |
| 2948 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2949 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2950 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2951 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2952 | { |
| 2953 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2954 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2955 | { |
| 2956 | return false; |
| 2957 | } |
| 2958 | } |
| 2959 | else |
| 2960 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2961 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2962 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2963 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2964 | data)) |
| 2965 | { |
| 2966 | return false; |
| 2967 | } |
| 2968 | } |
| 2969 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2970 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2971 | GLuint blockSize = 0; |
| 2972 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2973 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2974 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2975 | return false; |
| 2976 | } |
| 2977 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2978 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2979 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2980 | context->validationError(GL_INVALID_VALUE, kInvalidCompressedImageSize); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2981 | return false; |
| 2982 | } |
| 2983 | |
| 2984 | return true; |
| 2985 | } |
| 2986 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2987 | bool ValidateGetBufferPointervOES(Context *context, |
| 2988 | BufferBinding target, |
| 2989 | GLenum pname, |
| 2990 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2991 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2992 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2993 | } |
| 2994 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2995 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2996 | { |
| 2997 | if (!context->getExtensions().mapBuffer) |
| 2998 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2999 | context->validationError(GL_INVALID_OPERATION, "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3000 | return false; |
| 3001 | } |
| 3002 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3003 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3004 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3005 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3006 | return false; |
| 3007 | } |
| 3008 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3009 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3010 | |
| 3011 | if (buffer == nullptr) |
| 3012 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3013 | context->validationError(GL_INVALID_OPERATION, "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3014 | return false; |
| 3015 | } |
| 3016 | |
| 3017 | if (access != GL_WRITE_ONLY_OES) |
| 3018 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3019 | context->validationError(GL_INVALID_ENUM, "Non-write buffer mapping not supported."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3020 | return false; |
| 3021 | } |
| 3022 | |
| 3023 | if (buffer->isMapped()) |
| 3024 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3025 | context->validationError(GL_INVALID_OPERATION, "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3026 | return false; |
| 3027 | } |
| 3028 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3029 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3030 | } |
| 3031 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3032 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3033 | { |
| 3034 | if (!context->getExtensions().mapBuffer) |
| 3035 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3036 | context->validationError(GL_INVALID_OPERATION, "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3037 | return false; |
| 3038 | } |
| 3039 | |
| 3040 | return ValidateUnmapBufferBase(context, target); |
| 3041 | } |
| 3042 | |
| 3043 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3044 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3045 | GLintptr offset, |
| 3046 | GLsizeiptr length, |
| 3047 | GLbitfield access) |
| 3048 | { |
| 3049 | if (!context->getExtensions().mapBufferRange) |
| 3050 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3051 | context->validationError(GL_INVALID_OPERATION, "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3052 | return false; |
| 3053 | } |
| 3054 | |
| 3055 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 3056 | } |
| 3057 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3058 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3059 | { |
| 3060 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 3061 | ASSERT(buffer != nullptr); |
| 3062 | |
| 3063 | // Check if this buffer is currently being used as a transform feedback output buffer |
| 3064 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
| 3065 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 3066 | { |
| 3067 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3068 | { |
| 3069 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3070 | if (transformFeedbackBuffer.get() == buffer) |
| 3071 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3072 | context->validationError(GL_INVALID_OPERATION, |
| 3073 | "Buffer is currently bound for transform feedback."); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3074 | return false; |
| 3075 | } |
| 3076 | } |
| 3077 | } |
| 3078 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3079 | if (context->getExtensions().webglCompatibility && |
| 3080 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3081 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3082 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3083 | return false; |
| 3084 | } |
| 3085 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3086 | return true; |
| 3087 | } |
| 3088 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3089 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3090 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3091 | GLintptr offset, |
| 3092 | GLsizeiptr length) |
| 3093 | { |
| 3094 | if (!context->getExtensions().mapBufferRange) |
| 3095 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3096 | context->validationError(GL_INVALID_OPERATION, "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3097 | return false; |
| 3098 | } |
| 3099 | |
| 3100 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3101 | } |
| 3102 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3103 | bool ValidateBindTexture(Context *context, TextureType target, GLuint texture) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3104 | { |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 3105 | if (!context->getStateCache().isValidBindTextureType(target)) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3106 | { |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 3107 | RecordBindTextureTypeError(context, target); |
| 3108 | return false; |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3109 | } |
| 3110 | |
Jamie Madill | 0fdb956 | 2018-09-17 17:18:43 -0400 | [diff] [blame] | 3111 | if (texture == 0) |
| 3112 | { |
| 3113 | return true; |
| 3114 | } |
| 3115 | |
| 3116 | Texture *textureObject = context->getTexture(texture); |
| 3117 | if (textureObject && textureObject->getType() != target) |
| 3118 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3119 | context->validationError(GL_INVALID_OPERATION, kTypeMismatch); |
Jamie Madill | 0fdb956 | 2018-09-17 17:18:43 -0400 | [diff] [blame] | 3120 | return false; |
| 3121 | } |
| 3122 | |
| 3123 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 3124 | !context->isTextureGenerated(texture)) |
| 3125 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3126 | context->validationError(GL_INVALID_OPERATION, "Texture was not generated"); |
Jamie Madill | 0fdb956 | 2018-09-17 17:18:43 -0400 | [diff] [blame] | 3127 | return false; |
| 3128 | } |
| 3129 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3130 | return true; |
| 3131 | } |
| 3132 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3133 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 3134 | GLuint program, |
| 3135 | GLint location, |
| 3136 | const GLchar *name) |
| 3137 | { |
| 3138 | if (!context->getExtensions().bindUniformLocation) |
| 3139 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3140 | context->validationError(GL_INVALID_OPERATION, |
| 3141 | "GL_CHROMIUM_bind_uniform_location is not available."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3142 | return false; |
| 3143 | } |
| 3144 | |
| 3145 | Program *programObject = GetValidProgram(context, program); |
| 3146 | if (!programObject) |
| 3147 | { |
| 3148 | return false; |
| 3149 | } |
| 3150 | |
| 3151 | if (location < 0) |
| 3152 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3153 | context->validationError(GL_INVALID_VALUE, "Location cannot be less than 0."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3154 | return false; |
| 3155 | } |
| 3156 | |
| 3157 | const Caps &caps = context->getCaps(); |
| 3158 | if (static_cast<size_t>(location) >= |
| 3159 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3160 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3161 | context->validationError(GL_INVALID_VALUE, |
| 3162 | "Location must be less than " |
| 3163 | "(MAX_VERTEX_UNIFORM_VECTORS + " |
| 3164 | "MAX_FRAGMENT_UNIFORM_VECTORS) * 4"); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3165 | return false; |
| 3166 | } |
| 3167 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3168 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3169 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3170 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3171 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3172 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3173 | return false; |
| 3174 | } |
| 3175 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3176 | if (strncmp(name, "gl_", 3) == 0) |
| 3177 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3178 | context->validationError(GL_INVALID_VALUE, kNameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3179 | return false; |
| 3180 | } |
| 3181 | |
| 3182 | return true; |
| 3183 | } |
| 3184 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3185 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3186 | { |
| 3187 | if (!context->getExtensions().framebufferMixedSamples) |
| 3188 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3189 | context->validationError(GL_INVALID_OPERATION, |
| 3190 | "GL_CHROMIUM_framebuffer_mixed_samples is not available."); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3191 | return false; |
| 3192 | } |
| 3193 | switch (components) |
| 3194 | { |
| 3195 | case GL_RGB: |
| 3196 | case GL_RGBA: |
| 3197 | case GL_ALPHA: |
| 3198 | case GL_NONE: |
| 3199 | break; |
| 3200 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3201 | context->validationError( |
| 3202 | GL_INVALID_ENUM, |
| 3203 | "GLenum components is not one of GL_RGB, GL_RGBA, GL_ALPHA or GL_NONE."); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3204 | return false; |
| 3205 | } |
| 3206 | |
| 3207 | return true; |
| 3208 | } |
| 3209 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3210 | // CHROMIUM_path_rendering |
| 3211 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3212 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3213 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3214 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3215 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3216 | return false; |
| 3217 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3218 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3219 | if (matrix == nullptr) |
| 3220 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3221 | context->validationError(GL_INVALID_OPERATION, "Invalid matrix."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3222 | return false; |
| 3223 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3224 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3225 | return true; |
| 3226 | } |
| 3227 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3228 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3229 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3230 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3231 | } |
| 3232 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3233 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3234 | { |
| 3235 | if (!context->getExtensions().pathRendering) |
| 3236 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3237 | context->validationError(GL_INVALID_OPERATION, |
| 3238 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3239 | return false; |
| 3240 | } |
| 3241 | |
| 3242 | // range = 0 is undefined in NV_path_rendering. |
| 3243 | // we add stricter semantic check here and require a non zero positive range. |
| 3244 | if (range <= 0) |
| 3245 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3246 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3247 | return false; |
| 3248 | } |
| 3249 | |
| 3250 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3251 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3252 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3253 | return false; |
| 3254 | } |
| 3255 | |
| 3256 | return true; |
| 3257 | } |
| 3258 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3259 | bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3260 | { |
| 3261 | if (!context->getExtensions().pathRendering) |
| 3262 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3263 | context->validationError(GL_INVALID_OPERATION, |
| 3264 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3265 | return false; |
| 3266 | } |
| 3267 | |
| 3268 | // range = 0 is undefined in NV_path_rendering. |
| 3269 | // we add stricter semantic check here and require a non zero positive range. |
| 3270 | if (range <= 0) |
| 3271 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3272 | context->validationError(GL_INVALID_VALUE, kInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3273 | return false; |
| 3274 | } |
| 3275 | |
| 3276 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 3277 | checkedRange += range; |
| 3278 | |
| 3279 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3280 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3281 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3282 | return false; |
| 3283 | } |
| 3284 | return true; |
| 3285 | } |
| 3286 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3287 | bool ValidatePathCommandsCHROMIUM(Context *context, |
| 3288 | GLuint path, |
| 3289 | GLsizei numCommands, |
| 3290 | const GLubyte *commands, |
| 3291 | GLsizei numCoords, |
| 3292 | GLenum coordType, |
| 3293 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3294 | { |
| 3295 | if (!context->getExtensions().pathRendering) |
| 3296 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3297 | context->validationError(GL_INVALID_OPERATION, |
| 3298 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3299 | return false; |
| 3300 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3301 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3302 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3303 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3304 | return false; |
| 3305 | } |
| 3306 | |
| 3307 | if (numCommands < 0) |
| 3308 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3309 | context->validationError(GL_INVALID_VALUE, "Invalid number of commands."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3310 | return false; |
| 3311 | } |
| 3312 | else if (numCommands > 0) |
| 3313 | { |
| 3314 | if (!commands) |
| 3315 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3316 | context->validationError(GL_INVALID_VALUE, "No commands array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3317 | return false; |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | if (numCoords < 0) |
| 3322 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3323 | context->validationError(GL_INVALID_VALUE, "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3324 | return false; |
| 3325 | } |
| 3326 | else if (numCoords > 0) |
| 3327 | { |
| 3328 | if (!coords) |
| 3329 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3330 | context->validationError(GL_INVALID_VALUE, "No coordinate array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3331 | return false; |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | std::uint32_t coordTypeSize = 0; |
| 3336 | switch (coordType) |
| 3337 | { |
| 3338 | case GL_BYTE: |
| 3339 | coordTypeSize = sizeof(GLbyte); |
| 3340 | break; |
| 3341 | |
| 3342 | case GL_UNSIGNED_BYTE: |
| 3343 | coordTypeSize = sizeof(GLubyte); |
| 3344 | break; |
| 3345 | |
| 3346 | case GL_SHORT: |
| 3347 | coordTypeSize = sizeof(GLshort); |
| 3348 | break; |
| 3349 | |
| 3350 | case GL_UNSIGNED_SHORT: |
| 3351 | coordTypeSize = sizeof(GLushort); |
| 3352 | break; |
| 3353 | |
| 3354 | case GL_FLOAT: |
| 3355 | coordTypeSize = sizeof(GLfloat); |
| 3356 | break; |
| 3357 | |
| 3358 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3359 | context->validationError(GL_INVALID_ENUM, "Invalid coordinate type."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3360 | return false; |
| 3361 | } |
| 3362 | |
| 3363 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3364 | checkedSize += (coordTypeSize * numCoords); |
| 3365 | if (!checkedSize.IsValid()) |
| 3366 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3367 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3368 | return false; |
| 3369 | } |
| 3370 | |
| 3371 | // early return skips command data validation when it doesn't exist. |
| 3372 | if (!commands) |
| 3373 | return true; |
| 3374 | |
| 3375 | GLsizei expectedNumCoords = 0; |
| 3376 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3377 | { |
| 3378 | switch (commands[i]) |
| 3379 | { |
| 3380 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3381 | break; |
| 3382 | case GL_MOVE_TO_CHROMIUM: |
| 3383 | case GL_LINE_TO_CHROMIUM: |
| 3384 | expectedNumCoords += 2; |
| 3385 | break; |
| 3386 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3387 | expectedNumCoords += 4; |
| 3388 | break; |
| 3389 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3390 | expectedNumCoords += 6; |
| 3391 | break; |
| 3392 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3393 | expectedNumCoords += 5; |
| 3394 | break; |
| 3395 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3396 | context->validationError(GL_INVALID_ENUM, "Invalid command."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3397 | return false; |
| 3398 | } |
| 3399 | } |
| 3400 | if (expectedNumCoords != numCoords) |
| 3401 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3402 | context->validationError(GL_INVALID_VALUE, "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3403 | return false; |
| 3404 | } |
| 3405 | |
| 3406 | return true; |
| 3407 | } |
| 3408 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3409 | bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3410 | { |
| 3411 | if (!context->getExtensions().pathRendering) |
| 3412 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3413 | context->validationError(GL_INVALID_OPERATION, |
| 3414 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3415 | return false; |
| 3416 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3417 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3418 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3419 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3420 | return false; |
| 3421 | } |
| 3422 | |
| 3423 | switch (pname) |
| 3424 | { |
| 3425 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3426 | if (value < 0.0f) |
| 3427 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3428 | context->validationError(GL_INVALID_VALUE, "Invalid stroke width."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3429 | return false; |
| 3430 | } |
| 3431 | break; |
| 3432 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3433 | switch (static_cast<GLenum>(value)) |
| 3434 | { |
| 3435 | case GL_FLAT_CHROMIUM: |
| 3436 | case GL_SQUARE_CHROMIUM: |
| 3437 | case GL_ROUND_CHROMIUM: |
| 3438 | break; |
| 3439 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3440 | context->validationError(GL_INVALID_ENUM, "Invalid end caps."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3441 | return false; |
| 3442 | } |
| 3443 | break; |
| 3444 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3445 | switch (static_cast<GLenum>(value)) |
| 3446 | { |
| 3447 | case GL_MITER_REVERT_CHROMIUM: |
| 3448 | case GL_BEVEL_CHROMIUM: |
| 3449 | case GL_ROUND_CHROMIUM: |
| 3450 | break; |
| 3451 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3452 | context->validationError(GL_INVALID_ENUM, "Invalid join style."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3453 | return false; |
| 3454 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3455 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3456 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3457 | if (value < 0.0f) |
| 3458 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3459 | context->validationError(GL_INVALID_VALUE, "Invalid miter limit."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3460 | return false; |
| 3461 | } |
| 3462 | break; |
| 3463 | |
| 3464 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3465 | // no errors, only clamping. |
| 3466 | break; |
| 3467 | |
| 3468 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3469 | context->validationError(GL_INVALID_ENUM, "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3470 | return false; |
| 3471 | } |
| 3472 | return true; |
| 3473 | } |
| 3474 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3475 | bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value) |
| 3476 | { |
| 3477 | // TODO(jmadill): Use proper clamping cast. |
| 3478 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3479 | } |
| 3480 | |
| 3481 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3482 | { |
| 3483 | if (!context->getExtensions().pathRendering) |
| 3484 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3485 | context->validationError(GL_INVALID_OPERATION, |
| 3486 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3487 | return false; |
| 3488 | } |
| 3489 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3490 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3491 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3492 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3493 | return false; |
| 3494 | } |
| 3495 | if (!value) |
| 3496 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3497 | context->validationError(GL_INVALID_VALUE, "No value array."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3498 | return false; |
| 3499 | } |
| 3500 | |
| 3501 | switch (pname) |
| 3502 | { |
| 3503 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3504 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3505 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3506 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3507 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3508 | break; |
| 3509 | |
| 3510 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3511 | context->validationError(GL_INVALID_ENUM, "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3512 | return false; |
| 3513 | } |
| 3514 | |
| 3515 | return true; |
| 3516 | } |
| 3517 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3518 | bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value) |
| 3519 | { |
| 3520 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3521 | reinterpret_cast<GLfloat *>(value)); |
| 3522 | } |
| 3523 | |
| 3524 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3525 | { |
| 3526 | if (!context->getExtensions().pathRendering) |
| 3527 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3528 | context->validationError(GL_INVALID_OPERATION, |
| 3529 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3530 | return false; |
| 3531 | } |
| 3532 | |
| 3533 | switch (func) |
| 3534 | { |
| 3535 | case GL_NEVER: |
| 3536 | case GL_ALWAYS: |
| 3537 | case GL_LESS: |
| 3538 | case GL_LEQUAL: |
| 3539 | case GL_EQUAL: |
| 3540 | case GL_GEQUAL: |
| 3541 | case GL_GREATER: |
| 3542 | case GL_NOTEQUAL: |
| 3543 | break; |
| 3544 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3545 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3546 | return false; |
| 3547 | } |
| 3548 | |
| 3549 | return true; |
| 3550 | } |
| 3551 | |
| 3552 | // Note that the spec specifies that for the path drawing commands |
| 3553 | // if the path object is not an existing path object the command |
| 3554 | // does nothing and no error is generated. |
| 3555 | // However if the path object exists but has not been specified any |
| 3556 | // commands then an error is generated. |
| 3557 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3558 | bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3559 | { |
| 3560 | if (!context->getExtensions().pathRendering) |
| 3561 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3562 | context->validationError(GL_INVALID_OPERATION, |
| 3563 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3564 | return false; |
| 3565 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3566 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3567 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3568 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3569 | return false; |
| 3570 | } |
| 3571 | |
| 3572 | switch (fillMode) |
| 3573 | { |
| 3574 | case GL_COUNT_UP_CHROMIUM: |
| 3575 | case GL_COUNT_DOWN_CHROMIUM: |
| 3576 | break; |
| 3577 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3578 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3579 | return false; |
| 3580 | } |
| 3581 | |
| 3582 | if (!isPow2(mask + 1)) |
| 3583 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3584 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3585 | return false; |
| 3586 | } |
| 3587 | |
| 3588 | return true; |
| 3589 | } |
| 3590 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3591 | bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3592 | { |
| 3593 | if (!context->getExtensions().pathRendering) |
| 3594 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3595 | context->validationError(GL_INVALID_OPERATION, |
| 3596 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3597 | return false; |
| 3598 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3599 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3600 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3601 | context->validationError(GL_INVALID_OPERATION, "No such path or path has no data."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3602 | return false; |
| 3603 | } |
| 3604 | |
| 3605 | return true; |
| 3606 | } |
| 3607 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3608 | bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3609 | { |
| 3610 | if (!context->getExtensions().pathRendering) |
| 3611 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3612 | context->validationError(GL_INVALID_OPERATION, |
| 3613 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3614 | return false; |
| 3615 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3616 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3617 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3618 | context->validationError(GL_INVALID_OPERATION, kNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3619 | return false; |
| 3620 | } |
| 3621 | |
| 3622 | switch (coverMode) |
| 3623 | { |
| 3624 | case GL_CONVEX_HULL_CHROMIUM: |
| 3625 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3626 | break; |
| 3627 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3628 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3629 | return false; |
| 3630 | } |
| 3631 | return true; |
| 3632 | } |
| 3633 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 3634 | bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3635 | { |
| 3636 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3637 | } |
| 3638 | |
| 3639 | bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3640 | { |
| 3641 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3642 | } |
| 3643 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3644 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
| 3645 | GLuint path, |
| 3646 | GLenum fillMode, |
| 3647 | GLuint mask, |
| 3648 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3649 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3650 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 3651 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3652 | } |
| 3653 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3654 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
| 3655 | GLuint path, |
| 3656 | GLint reference, |
| 3657 | GLuint mask, |
| 3658 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3659 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3660 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 3661 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3662 | } |
| 3663 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3664 | bool ValidateIsPathCHROMIUM(Context *context, GLuint path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3665 | { |
| 3666 | if (!context->getExtensions().pathRendering) |
| 3667 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3668 | context->validationError(GL_INVALID_OPERATION, |
| 3669 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3670 | return false; |
| 3671 | } |
| 3672 | return true; |
| 3673 | } |
| 3674 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3675 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 3676 | GLsizei numPaths, |
| 3677 | GLenum pathNameType, |
| 3678 | const void *paths, |
| 3679 | GLuint pathBase, |
| 3680 | GLenum coverMode, |
| 3681 | GLenum transformType, |
| 3682 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3683 | { |
| 3684 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3685 | transformType, transformValues)) |
| 3686 | return false; |
| 3687 | |
| 3688 | switch (coverMode) |
| 3689 | { |
| 3690 | case GL_CONVEX_HULL_CHROMIUM: |
| 3691 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3692 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3693 | break; |
| 3694 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3695 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3696 | return false; |
| 3697 | } |
| 3698 | |
| 3699 | return true; |
| 3700 | } |
| 3701 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3702 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3703 | GLsizei numPaths, |
| 3704 | GLenum pathNameType, |
| 3705 | const void *paths, |
| 3706 | GLuint pathBase, |
| 3707 | GLenum coverMode, |
| 3708 | GLenum transformType, |
| 3709 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3710 | { |
| 3711 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3712 | transformType, transformValues)) |
| 3713 | return false; |
| 3714 | |
| 3715 | switch (coverMode) |
| 3716 | { |
| 3717 | case GL_CONVEX_HULL_CHROMIUM: |
| 3718 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3719 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3720 | break; |
| 3721 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3722 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3723 | return false; |
| 3724 | } |
| 3725 | |
| 3726 | return true; |
| 3727 | } |
| 3728 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3729 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 3730 | GLsizei numPaths, |
| 3731 | GLenum pathNameType, |
| 3732 | const void *paths, |
| 3733 | GLuint pathBase, |
| 3734 | GLenum fillMode, |
| 3735 | GLuint mask, |
| 3736 | GLenum transformType, |
| 3737 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3738 | { |
| 3739 | |
| 3740 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3741 | transformType, transformValues)) |
| 3742 | return false; |
| 3743 | |
| 3744 | switch (fillMode) |
| 3745 | { |
| 3746 | case GL_COUNT_UP_CHROMIUM: |
| 3747 | case GL_COUNT_DOWN_CHROMIUM: |
| 3748 | break; |
| 3749 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3750 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3751 | return false; |
| 3752 | } |
| 3753 | if (!isPow2(mask + 1)) |
| 3754 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3755 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3756 | return false; |
| 3757 | } |
| 3758 | return true; |
| 3759 | } |
| 3760 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3761 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 3762 | GLsizei numPaths, |
| 3763 | GLenum pathNameType, |
| 3764 | const void *paths, |
| 3765 | GLuint pathBase, |
| 3766 | GLint reference, |
| 3767 | GLuint mask, |
| 3768 | GLenum transformType, |
| 3769 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3770 | { |
| 3771 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3772 | transformType, transformValues)) |
| 3773 | return false; |
| 3774 | |
| 3775 | // no more validation here. |
| 3776 | |
| 3777 | return true; |
| 3778 | } |
| 3779 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3780 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 3781 | GLsizei numPaths, |
| 3782 | GLenum pathNameType, |
| 3783 | const void *paths, |
| 3784 | GLuint pathBase, |
| 3785 | GLenum fillMode, |
| 3786 | GLuint mask, |
| 3787 | GLenum coverMode, |
| 3788 | GLenum transformType, |
| 3789 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3790 | { |
| 3791 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3792 | transformType, transformValues)) |
| 3793 | return false; |
| 3794 | |
| 3795 | switch (coverMode) |
| 3796 | { |
| 3797 | case GL_CONVEX_HULL_CHROMIUM: |
| 3798 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3799 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3800 | break; |
| 3801 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3802 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3803 | return false; |
| 3804 | } |
| 3805 | |
| 3806 | switch (fillMode) |
| 3807 | { |
| 3808 | case GL_COUNT_UP_CHROMIUM: |
| 3809 | case GL_COUNT_DOWN_CHROMIUM: |
| 3810 | break; |
| 3811 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3812 | context->validationError(GL_INVALID_ENUM, kInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3813 | return false; |
| 3814 | } |
| 3815 | if (!isPow2(mask + 1)) |
| 3816 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3817 | context->validationError(GL_INVALID_VALUE, kInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3818 | return false; |
| 3819 | } |
| 3820 | |
| 3821 | return true; |
| 3822 | } |
| 3823 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3824 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3825 | GLsizei numPaths, |
| 3826 | GLenum pathNameType, |
| 3827 | const void *paths, |
| 3828 | GLuint pathBase, |
| 3829 | GLint reference, |
| 3830 | GLuint mask, |
| 3831 | GLenum coverMode, |
| 3832 | GLenum transformType, |
| 3833 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3834 | { |
| 3835 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3836 | transformType, transformValues)) |
| 3837 | return false; |
| 3838 | |
| 3839 | switch (coverMode) |
| 3840 | { |
| 3841 | case GL_CONVEX_HULL_CHROMIUM: |
| 3842 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3843 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3844 | break; |
| 3845 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3846 | context->validationError(GL_INVALID_ENUM, kInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3847 | return false; |
| 3848 | } |
| 3849 | |
| 3850 | return true; |
| 3851 | } |
| 3852 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3853 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
| 3854 | GLuint program, |
| 3855 | GLint location, |
| 3856 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3857 | { |
| 3858 | if (!context->getExtensions().pathRendering) |
| 3859 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3860 | context->validationError(GL_INVALID_OPERATION, |
| 3861 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3862 | return false; |
| 3863 | } |
| 3864 | |
| 3865 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 3866 | if (location >= MaxLocation) |
| 3867 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3868 | context->validationError(GL_INVALID_VALUE, "Location exceeds max varying."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3869 | return false; |
| 3870 | } |
| 3871 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3872 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3873 | if (!programObject) |
| 3874 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3875 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3876 | return false; |
| 3877 | } |
| 3878 | |
| 3879 | if (!name) |
| 3880 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3881 | context->validationError(GL_INVALID_VALUE, "No name given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3882 | return false; |
| 3883 | } |
| 3884 | |
| 3885 | if (angle::BeginsWith(name, "gl_")) |
| 3886 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3887 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3888 | return false; |
| 3889 | } |
| 3890 | |
| 3891 | return true; |
| 3892 | } |
| 3893 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3894 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
| 3895 | GLuint program, |
| 3896 | GLint location, |
| 3897 | GLenum genMode, |
| 3898 | GLint components, |
| 3899 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3900 | { |
| 3901 | if (!context->getExtensions().pathRendering) |
| 3902 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3903 | context->validationError(GL_INVALID_OPERATION, |
| 3904 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3905 | return false; |
| 3906 | } |
| 3907 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3908 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3909 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 3910 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3911 | context->validationError(GL_INVALID_OPERATION, kProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3912 | return false; |
| 3913 | } |
| 3914 | |
| 3915 | if (!programObject->isLinked()) |
| 3916 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3917 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3918 | return false; |
| 3919 | } |
| 3920 | |
| 3921 | switch (genMode) |
| 3922 | { |
| 3923 | case GL_NONE: |
| 3924 | if (components != 0) |
| 3925 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3926 | context->validationError(GL_INVALID_VALUE, "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3927 | return false; |
| 3928 | } |
| 3929 | break; |
| 3930 | |
| 3931 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 3932 | case GL_EYE_LINEAR_CHROMIUM: |
| 3933 | case GL_CONSTANT_CHROMIUM: |
| 3934 | if (components < 1 || components > 4) |
| 3935 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3936 | context->validationError(GL_INVALID_VALUE, "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3937 | return false; |
| 3938 | } |
| 3939 | if (!coeffs) |
| 3940 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3941 | context->validationError(GL_INVALID_VALUE, "No coefficients array given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3942 | return false; |
| 3943 | } |
| 3944 | break; |
| 3945 | |
| 3946 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3947 | context->validationError(GL_INVALID_ENUM, "Invalid gen mode."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3948 | return false; |
| 3949 | } |
| 3950 | |
| 3951 | // If the location is -1 then the command is silently ignored |
| 3952 | // and no further validation is needed. |
| 3953 | if (location == -1) |
| 3954 | return true; |
| 3955 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3956 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3957 | |
| 3958 | if (!binding.valid) |
| 3959 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3960 | context->validationError(GL_INVALID_OPERATION, "No such binding."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3961 | return false; |
| 3962 | } |
| 3963 | |
| 3964 | if (binding.type != GL_NONE) |
| 3965 | { |
| 3966 | GLint expectedComponents = 0; |
| 3967 | switch (binding.type) |
| 3968 | { |
| 3969 | case GL_FLOAT: |
| 3970 | expectedComponents = 1; |
| 3971 | break; |
| 3972 | case GL_FLOAT_VEC2: |
| 3973 | expectedComponents = 2; |
| 3974 | break; |
| 3975 | case GL_FLOAT_VEC3: |
| 3976 | expectedComponents = 3; |
| 3977 | break; |
| 3978 | case GL_FLOAT_VEC4: |
| 3979 | expectedComponents = 4; |
| 3980 | break; |
| 3981 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3982 | context->validationError( |
| 3983 | GL_INVALID_OPERATION, |
| 3984 | "Fragment input type is not a floating point scalar or vector."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3985 | return false; |
| 3986 | } |
| 3987 | if (expectedComponents != components && genMode != GL_NONE) |
| 3988 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3989 | context->validationError(GL_INVALID_OPERATION, "Unexpected number of components"); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3990 | return false; |
| 3991 | } |
| 3992 | } |
| 3993 | return true; |
| 3994 | } |
| 3995 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3996 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 3997 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3998 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3999 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4000 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4001 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4002 | GLint internalFormat, |
| 4003 | GLenum destType, |
| 4004 | GLboolean unpackFlipY, |
| 4005 | GLboolean unpackPremultiplyAlpha, |
| 4006 | GLboolean unpackUnmultiplyAlpha) |
| 4007 | { |
| 4008 | if (!context->getExtensions().copyTexture) |
| 4009 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4010 | context->validationError(GL_INVALID_OPERATION, |
| 4011 | "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4012 | return false; |
| 4013 | } |
| 4014 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4015 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4016 | if (source == nullptr) |
| 4017 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4018 | context->validationError(GL_INVALID_VALUE, "Source texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4019 | return false; |
| 4020 | } |
| 4021 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4022 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4023 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4024 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4025 | return false; |
| 4026 | } |
| 4027 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4028 | TextureType sourceType = source->getType(); |
| 4029 | ASSERT(sourceType != TextureType::CubeMap); |
| 4030 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4031 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4032 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4033 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4034 | context->validationError(GL_INVALID_VALUE, "Source texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4035 | return false; |
| 4036 | } |
| 4037 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4038 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 4039 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 4040 | if (sourceWidth == 0 || sourceHeight == 0) |
| 4041 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4042 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4043 | return false; |
| 4044 | } |
| 4045 | |
| 4046 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 4047 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4048 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4049 | context->validationError(GL_INVALID_OPERATION, |
| 4050 | "Source texture internal format is invalid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4051 | return false; |
| 4052 | } |
| 4053 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4054 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4055 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4056 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4057 | return false; |
| 4058 | } |
| 4059 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4060 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4061 | if (dest == nullptr) |
| 4062 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4063 | context->validationError(GL_INVALID_VALUE, |
| 4064 | "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4065 | return false; |
| 4066 | } |
| 4067 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4068 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4069 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4070 | context->validationError(GL_INVALID_VALUE, "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4071 | return false; |
| 4072 | } |
| 4073 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4074 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4075 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4076 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4077 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4078 | return false; |
| 4079 | } |
| 4080 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4081 | if (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 4082 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4083 | return false; |
| 4084 | } |
| 4085 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4086 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4087 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4088 | context->validationError( |
| 4089 | GL_INVALID_VALUE, "Destination width and height must be equal for cube map textures."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4090 | return false; |
| 4091 | } |
| 4092 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4093 | if (dest->getImmutableFormat()) |
| 4094 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4095 | context->validationError(GL_INVALID_OPERATION, "Destination texture is immutable."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4096 | return false; |
| 4097 | } |
| 4098 | |
| 4099 | return true; |
| 4100 | } |
| 4101 | |
| 4102 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 4103 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4104 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4105 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4106 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4107 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4108 | GLint xoffset, |
| 4109 | GLint yoffset, |
| 4110 | GLint x, |
| 4111 | GLint y, |
| 4112 | GLsizei width, |
| 4113 | GLsizei height, |
| 4114 | GLboolean unpackFlipY, |
| 4115 | GLboolean unpackPremultiplyAlpha, |
| 4116 | GLboolean unpackUnmultiplyAlpha) |
| 4117 | { |
| 4118 | if (!context->getExtensions().copyTexture) |
| 4119 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4120 | context->validationError(GL_INVALID_OPERATION, |
| 4121 | "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4122 | return false; |
| 4123 | } |
| 4124 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4125 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4126 | if (source == nullptr) |
| 4127 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4128 | context->validationError(GL_INVALID_VALUE, "Source texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4129 | return false; |
| 4130 | } |
| 4131 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4132 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4133 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4134 | context->validationError(GL_INVALID_VALUE, "Source texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4135 | return false; |
| 4136 | } |
| 4137 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4138 | TextureType sourceType = source->getType(); |
| 4139 | ASSERT(sourceType != TextureType::CubeMap); |
| 4140 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4141 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4142 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4143 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4144 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4145 | return false; |
| 4146 | } |
| 4147 | |
| 4148 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4149 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4150 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4151 | context->validationError(GL_INVALID_VALUE, |
| 4152 | "The source level of the source texture must be defined."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4153 | return false; |
| 4154 | } |
| 4155 | |
| 4156 | if (x < 0 || y < 0) |
| 4157 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4158 | context->validationError(GL_INVALID_VALUE, "x and y cannot be negative."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4159 | return false; |
| 4160 | } |
| 4161 | |
| 4162 | if (width < 0 || height < 0) |
| 4163 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4164 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4165 | return false; |
| 4166 | } |
| 4167 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4168 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4169 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4170 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4171 | context->validationError(GL_INVALID_VALUE, kSourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4172 | return false; |
| 4173 | } |
| 4174 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4175 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4176 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4177 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4178 | context->validationError(GL_INVALID_OPERATION, kInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4179 | return false; |
| 4180 | } |
| 4181 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4182 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4183 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4184 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4185 | return false; |
| 4186 | } |
| 4187 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4188 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4189 | if (dest == nullptr) |
| 4190 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4191 | context->validationError(GL_INVALID_VALUE, |
| 4192 | "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4193 | return false; |
| 4194 | } |
| 4195 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4196 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4197 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4198 | context->validationError(GL_INVALID_VALUE, "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4199 | return false; |
| 4200 | } |
| 4201 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4202 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4203 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4204 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4205 | context->validationError(GL_INVALID_VALUE, "Destination texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4206 | return false; |
| 4207 | } |
| 4208 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4209 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4210 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4211 | context->validationError( |
| 4212 | GL_INVALID_OPERATION, |
| 4213 | "The destination level of the destination texture must be defined."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4214 | return false; |
| 4215 | } |
| 4216 | |
| 4217 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4218 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4219 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4220 | context->validationError(GL_INVALID_OPERATION, |
| 4221 | "Destination internal format and type combination is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4222 | return false; |
| 4223 | } |
| 4224 | |
| 4225 | if (xoffset < 0 || yoffset < 0) |
| 4226 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4227 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4228 | return false; |
| 4229 | } |
| 4230 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4231 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4232 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4233 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4234 | context->validationError(GL_INVALID_VALUE, |
| 4235 | "Destination texture not large enough to copy to."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4236 | return false; |
| 4237 | } |
| 4238 | |
| 4239 | return true; |
| 4240 | } |
| 4241 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4242 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 4243 | { |
| 4244 | if (!context->getExtensions().copyCompressedTexture) |
| 4245 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4246 | context->validationError(GL_INVALID_OPERATION, |
| 4247 | "GL_CHROMIUM_copy_compressed_texture extension not available."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4248 | return false; |
| 4249 | } |
| 4250 | |
| 4251 | const gl::Texture *source = context->getTexture(sourceId); |
| 4252 | if (source == nullptr) |
| 4253 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4254 | context->validationError(GL_INVALID_VALUE, "Source texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4255 | return false; |
| 4256 | } |
| 4257 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4258 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4259 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4260 | context->validationError(GL_INVALID_VALUE, "Source texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4261 | return false; |
| 4262 | } |
| 4263 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4264 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4265 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4266 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4267 | context->validationError(GL_INVALID_VALUE, "Source texture must level 0 defined."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4268 | return false; |
| 4269 | } |
| 4270 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4271 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4272 | if (!sourceFormat.info->compressed) |
| 4273 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4274 | context->validationError(GL_INVALID_OPERATION, |
| 4275 | "Source texture must have a compressed internal format."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4276 | return false; |
| 4277 | } |
| 4278 | |
| 4279 | const gl::Texture *dest = context->getTexture(destId); |
| 4280 | if (dest == nullptr) |
| 4281 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4282 | context->validationError(GL_INVALID_VALUE, |
| 4283 | "Destination texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4284 | return false; |
| 4285 | } |
| 4286 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4287 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4288 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4289 | context->validationError(GL_INVALID_VALUE, |
| 4290 | "Destination texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4291 | return false; |
| 4292 | } |
| 4293 | |
| 4294 | if (dest->getImmutableFormat()) |
| 4295 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4296 | context->validationError(GL_INVALID_OPERATION, "Destination cannot be immutable."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4297 | return false; |
| 4298 | } |
| 4299 | |
| 4300 | return true; |
| 4301 | } |
| 4302 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4303 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4304 | { |
| 4305 | switch (type) |
| 4306 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4307 | case ShaderType::Vertex: |
| 4308 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4309 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4310 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4311 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4312 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4313 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4314 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4315 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4316 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4317 | break; |
| 4318 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4319 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4320 | if (!context->getExtensions().geometryShader) |
| 4321 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4322 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4323 | return false; |
| 4324 | } |
| 4325 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4326 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4327 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4328 | return false; |
| 4329 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4330 | |
| 4331 | return true; |
| 4332 | } |
| 4333 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4334 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4335 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4336 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4337 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4338 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4339 | { |
| 4340 | if (size < 0) |
| 4341 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4342 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4343 | return false; |
| 4344 | } |
| 4345 | |
| 4346 | switch (usage) |
| 4347 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4348 | case BufferUsage::StreamDraw: |
| 4349 | case BufferUsage::StaticDraw: |
| 4350 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4351 | break; |
| 4352 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4353 | case BufferUsage::StreamRead: |
| 4354 | case BufferUsage::StaticRead: |
| 4355 | case BufferUsage::DynamicRead: |
| 4356 | case BufferUsage::StreamCopy: |
| 4357 | case BufferUsage::StaticCopy: |
| 4358 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4359 | if (context->getClientMajorVersion() < 3) |
| 4360 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4361 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4362 | return false; |
| 4363 | } |
| 4364 | break; |
| 4365 | |
| 4366 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4367 | context->validationError(GL_INVALID_ENUM, kInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4368 | return false; |
| 4369 | } |
| 4370 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4371 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4372 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4373 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4374 | return false; |
| 4375 | } |
| 4376 | |
| 4377 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4378 | |
| 4379 | if (!buffer) |
| 4380 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4381 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4382 | return false; |
| 4383 | } |
| 4384 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4385 | if (context->getExtensions().webglCompatibility && |
| 4386 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4387 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4388 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4389 | return false; |
| 4390 | } |
| 4391 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4392 | return true; |
| 4393 | } |
| 4394 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4395 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4396 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4397 | GLintptr offset, |
| 4398 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4399 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4400 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4401 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4402 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4403 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4404 | return false; |
| 4405 | } |
| 4406 | |
| 4407 | if (offset < 0) |
| 4408 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4409 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4410 | return false; |
| 4411 | } |
| 4412 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4413 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4414 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4415 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4416 | return false; |
| 4417 | } |
| 4418 | |
| 4419 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4420 | |
| 4421 | if (!buffer) |
| 4422 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4423 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4424 | return false; |
| 4425 | } |
| 4426 | |
| 4427 | if (buffer->isMapped()) |
| 4428 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4429 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4430 | return false; |
| 4431 | } |
| 4432 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4433 | if (context->getExtensions().webglCompatibility && |
| 4434 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4435 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4436 | context->validationError(GL_INVALID_OPERATION, kBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4437 | return false; |
| 4438 | } |
| 4439 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4440 | // Check for possible overflow of size + offset |
| 4441 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4442 | checkedSize += offset; |
| 4443 | if (!checkedSize.IsValid()) |
| 4444 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4445 | context->validationError(GL_INVALID_VALUE, kParamOverflow); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4446 | return false; |
| 4447 | } |
| 4448 | |
| 4449 | if (size + offset > buffer->getSize()) |
| 4450 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4451 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4452 | return false; |
| 4453 | } |
| 4454 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4455 | return true; |
| 4456 | } |
| 4457 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4458 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4459 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4460 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4461 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4462 | context->validationError(GL_INVALID_OPERATION, |
| 4463 | "GL_ANGLE_request_extension is not available."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4464 | return false; |
| 4465 | } |
| 4466 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4467 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4468 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4469 | context->validationError(GL_INVALID_OPERATION, "Extension is not requestable."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4470 | return false; |
| 4471 | } |
| 4472 | |
| 4473 | return true; |
| 4474 | } |
| 4475 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4476 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4477 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4478 | if (context->getClientMajorVersion() < 2) |
| 4479 | { |
| 4480 | return ValidateMultitextureUnit(context, texture); |
| 4481 | } |
| 4482 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4483 | if (texture < GL_TEXTURE0 || |
| 4484 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4485 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4486 | context->validationError(GL_INVALID_ENUM, kInvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4487 | return false; |
| 4488 | } |
| 4489 | |
| 4490 | return true; |
| 4491 | } |
| 4492 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4493 | bool ValidateAttachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4494 | { |
| 4495 | Program *programObject = GetValidProgram(context, program); |
| 4496 | if (!programObject) |
| 4497 | { |
| 4498 | return false; |
| 4499 | } |
| 4500 | |
| 4501 | Shader *shaderObject = GetValidShader(context, shader); |
| 4502 | if (!shaderObject) |
| 4503 | { |
| 4504 | return false; |
| 4505 | } |
| 4506 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4507 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4508 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4509 | context->validationError(GL_INVALID_OPERATION, kShaderAttachmentHasShader); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4510 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | return true; |
| 4514 | } |
| 4515 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4516 | bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4517 | { |
| 4518 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4519 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4520 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4521 | return false; |
| 4522 | } |
| 4523 | |
| 4524 | if (strncmp(name, "gl_", 3) == 0) |
| 4525 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4526 | context->validationError(GL_INVALID_OPERATION, kNameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4527 | return false; |
| 4528 | } |
| 4529 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4530 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4531 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4532 | const size_t length = strlen(name); |
| 4533 | |
| 4534 | if (!IsValidESSLString(name, length)) |
| 4535 | { |
| 4536 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4537 | // for shader-related entry points |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4538 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4539 | return false; |
| 4540 | } |
| 4541 | |
| 4542 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4543 | { |
| 4544 | return false; |
| 4545 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4546 | } |
| 4547 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4548 | return GetValidProgram(context, program) != nullptr; |
| 4549 | } |
| 4550 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4551 | bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4552 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4553 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4554 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4555 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4556 | return false; |
| 4557 | } |
| 4558 | |
| 4559 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4560 | !context->isFramebufferGenerated(framebuffer)) |
| 4561 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4562 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4563 | return false; |
| 4564 | } |
| 4565 | |
| 4566 | return true; |
| 4567 | } |
| 4568 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4569 | bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4570 | { |
| 4571 | if (target != GL_RENDERBUFFER) |
| 4572 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4573 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4574 | return false; |
| 4575 | } |
| 4576 | |
| 4577 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4578 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4579 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4580 | context->validationError(GL_INVALID_OPERATION, kObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4581 | return false; |
| 4582 | } |
| 4583 | |
| 4584 | return true; |
| 4585 | } |
| 4586 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4587 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4588 | { |
| 4589 | switch (mode) |
| 4590 | { |
| 4591 | case GL_FUNC_ADD: |
| 4592 | case GL_FUNC_SUBTRACT: |
| 4593 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4594 | return true; |
| 4595 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4596 | case GL_MIN: |
| 4597 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4598 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4599 | |
| 4600 | default: |
| 4601 | return false; |
| 4602 | } |
| 4603 | } |
| 4604 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4605 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4606 | { |
| 4607 | return true; |
| 4608 | } |
| 4609 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4610 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4611 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4612 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4613 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4614 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4615 | return false; |
| 4616 | } |
| 4617 | |
| 4618 | return true; |
| 4619 | } |
| 4620 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4621 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4622 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4623 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4624 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4625 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4626 | return false; |
| 4627 | } |
| 4628 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4629 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4630 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4631 | context->validationError(GL_INVALID_ENUM, kInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4632 | return false; |
| 4633 | } |
| 4634 | |
| 4635 | return true; |
| 4636 | } |
| 4637 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4638 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4639 | { |
| 4640 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 4641 | } |
| 4642 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4643 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4644 | GLenum srcRGB, |
| 4645 | GLenum dstRGB, |
| 4646 | GLenum srcAlpha, |
| 4647 | GLenum dstAlpha) |
| 4648 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4649 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4650 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4651 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4652 | return false; |
| 4653 | } |
| 4654 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4655 | if (!ValidDstBlendFunc(context, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4656 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4657 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4658 | return false; |
| 4659 | } |
| 4660 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4661 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4662 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4663 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4664 | return false; |
| 4665 | } |
| 4666 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4667 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4668 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4669 | context->validationError(GL_INVALID_ENUM, kInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4670 | return false; |
| 4671 | } |
| 4672 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4673 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 4674 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4675 | { |
| 4676 | bool constantColorUsed = |
| 4677 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 4678 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 4679 | |
| 4680 | bool constantAlphaUsed = |
| 4681 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 4682 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 4683 | |
| 4684 | if (constantColorUsed && constantAlphaUsed) |
| 4685 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4686 | const char *msg; |
| 4687 | if (context->getExtensions().webglCompatibility) |
| 4688 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4689 | msg = kInvalidConstantColor; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4690 | } |
| 4691 | else |
| 4692 | { |
| 4693 | msg = |
| 4694 | "Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and " |
| 4695 | "GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR not supported by this " |
| 4696 | "implementation."; |
Jamie Madill | a2f043d | 2018-07-10 17:21:20 -0400 | [diff] [blame] | 4697 | WARN() << msg; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4698 | } |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4699 | context->validationError(GL_INVALID_OPERATION, msg); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4700 | return false; |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | return true; |
| 4705 | } |
| 4706 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4707 | bool ValidateGetString(Context *context, GLenum name) |
| 4708 | { |
| 4709 | switch (name) |
| 4710 | { |
| 4711 | case GL_VENDOR: |
| 4712 | case GL_RENDERER: |
| 4713 | case GL_VERSION: |
| 4714 | case GL_SHADING_LANGUAGE_VERSION: |
| 4715 | case GL_EXTENSIONS: |
| 4716 | break; |
| 4717 | |
| 4718 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 4719 | if (!context->getExtensions().requestExtension) |
| 4720 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4721 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4722 | return false; |
| 4723 | } |
| 4724 | break; |
| 4725 | |
| 4726 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4727 | context->validationError(GL_INVALID_ENUM, kInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4728 | return false; |
| 4729 | } |
| 4730 | |
| 4731 | return true; |
| 4732 | } |
| 4733 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4734 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4735 | { |
| 4736 | if (width <= 0.0f || isNaN(width)) |
| 4737 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4738 | context->validationError(GL_INVALID_VALUE, kInvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4739 | return false; |
| 4740 | } |
| 4741 | |
| 4742 | return true; |
| 4743 | } |
| 4744 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4745 | bool ValidateVertexAttribPointer(Context *context, |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4746 | GLuint index, |
| 4747 | GLint size, |
| 4748 | GLenum type, |
| 4749 | GLboolean normalized, |
| 4750 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4751 | const void *ptr) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4752 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4753 | if (!ValidateVertexFormatBase(context, index, size, type, false)) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4754 | { |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4755 | return false; |
| 4756 | } |
| 4757 | |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4758 | if (stride < 0) |
| 4759 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4760 | context->validationError(GL_INVALID_VALUE, kNegativeStride); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4761 | return false; |
| 4762 | } |
| 4763 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4764 | const Caps &caps = context->getCaps(); |
| 4765 | if (context->getClientVersion() >= ES_3_1) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4766 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4767 | if (stride > caps.maxVertexAttribStride) |
| 4768 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4769 | context->validationError(GL_INVALID_VALUE, |
| 4770 | "stride cannot be greater than MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4771 | return false; |
| 4772 | } |
| 4773 | |
| 4774 | if (index >= caps.maxVertexAttribBindings) |
| 4775 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4776 | context->validationError(GL_INVALID_VALUE, |
| 4777 | "index must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4778 | return false; |
| 4779 | } |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | // [OpenGL ES 3.0.2] Section 2.8 page 24: |
| 4783 | // An INVALID_OPERATION error is generated when a non-zero vertex array object |
| 4784 | // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point, |
| 4785 | // and the pointer argument is not NULL. |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 4786 | bool nullBufferAllowed = context->getGLState().areClientArraysEnabled() && |
| 4787 | context->getGLState().getVertexArray()->id() == 0; |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4788 | if (!nullBufferAllowed && context->getGLState().getTargetBuffer(BufferBinding::Array) == 0 && |
| 4789 | ptr != nullptr) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4790 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4791 | context->validationError( |
| 4792 | GL_INVALID_OPERATION, |
| 4793 | "Client data cannot be used with a non-default vertex array object."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4794 | return false; |
| 4795 | } |
| 4796 | |
| 4797 | if (context->getExtensions().webglCompatibility) |
| 4798 | { |
| 4799 | // WebGL 1.0 [Section 6.14] Fixed point support |
| 4800 | // The WebGL API does not support the GL_FIXED data type. |
| 4801 | if (type == GL_FIXED) |
| 4802 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4803 | context->validationError(GL_INVALID_ENUM, "GL_FIXED is not supported in WebGL."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4804 | return false; |
| 4805 | } |
| 4806 | |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 4807 | if (!ValidateWebGLVertexAttribPointer(context, type, normalized, stride, ptr, false)) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4808 | { |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4809 | return false; |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | return true; |
| 4814 | } |
| 4815 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4816 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4817 | { |
| 4818 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 4819 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4820 | context->validationError(GL_INVALID_OPERATION, kInvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4821 | return false; |
| 4822 | } |
| 4823 | |
| 4824 | return true; |
| 4825 | } |
| 4826 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4827 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4828 | GLenum target, |
| 4829 | GLenum internalformat, |
| 4830 | GLsizei width, |
| 4831 | GLsizei height) |
| 4832 | { |
| 4833 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 4834 | height); |
| 4835 | } |
| 4836 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4837 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4838 | GLenum target, |
| 4839 | GLsizei samples, |
| 4840 | GLenum internalformat, |
| 4841 | GLsizei width, |
| 4842 | GLsizei height) |
| 4843 | { |
| 4844 | if (!context->getExtensions().framebufferMultisample) |
| 4845 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4846 | context->validationError(GL_INVALID_OPERATION, |
| 4847 | "GL_ANGLE_framebuffer_multisample not available"); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4848 | return false; |
| 4849 | } |
| 4850 | |
| 4851 | // 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] | 4852 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4853 | // generated. |
| 4854 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 4855 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4856 | context->validationError(GL_INVALID_VALUE, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4857 | return false; |
| 4858 | } |
| 4859 | |
| 4860 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 4861 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 4862 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 4863 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 4864 | if (context->getClientMajorVersion() >= 3) |
| 4865 | { |
| 4866 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 4867 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 4868 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4869 | context->validationError(GL_OUT_OF_MEMORY, kSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4870 | return false; |
| 4871 | } |
| 4872 | } |
| 4873 | |
| 4874 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 4875 | width, height); |
| 4876 | } |
| 4877 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4878 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4879 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4880 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4881 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4882 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4883 | return false; |
| 4884 | } |
| 4885 | |
| 4886 | return true; |
| 4887 | } |
| 4888 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4889 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4890 | { |
| 4891 | return true; |
| 4892 | } |
| 4893 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4894 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4895 | { |
| 4896 | return true; |
| 4897 | } |
| 4898 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4899 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4900 | { |
| 4901 | return true; |
| 4902 | } |
| 4903 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4904 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4905 | GLboolean red, |
| 4906 | GLboolean green, |
| 4907 | GLboolean blue, |
| 4908 | GLboolean alpha) |
| 4909 | { |
| 4910 | return true; |
| 4911 | } |
| 4912 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4913 | bool ValidateCompileShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4914 | { |
| 4915 | return true; |
| 4916 | } |
| 4917 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4918 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4919 | { |
| 4920 | return true; |
| 4921 | } |
| 4922 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4923 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4924 | { |
| 4925 | switch (mode) |
| 4926 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4927 | case CullFaceMode::Front: |
| 4928 | case CullFaceMode::Back: |
| 4929 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4930 | break; |
| 4931 | |
| 4932 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4933 | context->validationError(GL_INVALID_ENUM, kInvalidCullMode); |
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 ValidateDeleteProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4941 | { |
| 4942 | if (program == 0) |
| 4943 | { |
| 4944 | return false; |
| 4945 | } |
| 4946 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4947 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4948 | { |
| 4949 | if (context->getShader(program)) |
| 4950 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4951 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4952 | return false; |
| 4953 | } |
| 4954 | else |
| 4955 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4956 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4957 | return false; |
| 4958 | } |
| 4959 | } |
| 4960 | |
| 4961 | return true; |
| 4962 | } |
| 4963 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4964 | bool ValidateDeleteShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4965 | { |
| 4966 | if (shader == 0) |
| 4967 | { |
| 4968 | return false; |
| 4969 | } |
| 4970 | |
| 4971 | if (!context->getShader(shader)) |
| 4972 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4973 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4974 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4975 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4976 | return false; |
| 4977 | } |
| 4978 | else |
| 4979 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4980 | context->validationError(GL_INVALID_VALUE, kExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4981 | return false; |
| 4982 | } |
| 4983 | } |
| 4984 | |
| 4985 | return true; |
| 4986 | } |
| 4987 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4988 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4989 | { |
| 4990 | switch (func) |
| 4991 | { |
| 4992 | case GL_NEVER: |
| 4993 | case GL_ALWAYS: |
| 4994 | case GL_LESS: |
| 4995 | case GL_LEQUAL: |
| 4996 | case GL_EQUAL: |
| 4997 | case GL_GREATER: |
| 4998 | case GL_GEQUAL: |
| 4999 | case GL_NOTEQUAL: |
| 5000 | break; |
| 5001 | |
| 5002 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5003 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5004 | return false; |
| 5005 | } |
| 5006 | |
| 5007 | return true; |
| 5008 | } |
| 5009 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5010 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5011 | { |
| 5012 | return true; |
| 5013 | } |
| 5014 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5015 | bool ValidateDetachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5016 | { |
| 5017 | Program *programObject = GetValidProgram(context, program); |
| 5018 | if (!programObject) |
| 5019 | { |
| 5020 | return false; |
| 5021 | } |
| 5022 | |
| 5023 | Shader *shaderObject = GetValidShader(context, shader); |
| 5024 | if (!shaderObject) |
| 5025 | { |
| 5026 | return false; |
| 5027 | } |
| 5028 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5029 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5030 | if (attachedShader != shaderObject) |
| 5031 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5032 | context->validationError(GL_INVALID_OPERATION, kShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5033 | return false; |
| 5034 | } |
| 5035 | |
| 5036 | return true; |
| 5037 | } |
| 5038 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5039 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5040 | { |
| 5041 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5042 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5043 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5044 | return false; |
| 5045 | } |
| 5046 | |
| 5047 | return true; |
| 5048 | } |
| 5049 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5050 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5051 | { |
| 5052 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5053 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5054 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5055 | return false; |
| 5056 | } |
| 5057 | |
| 5058 | return true; |
| 5059 | } |
| 5060 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5061 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5062 | { |
| 5063 | return true; |
| 5064 | } |
| 5065 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5066 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5067 | { |
| 5068 | return true; |
| 5069 | } |
| 5070 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5071 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5072 | { |
| 5073 | switch (mode) |
| 5074 | { |
| 5075 | case GL_CW: |
| 5076 | case GL_CCW: |
| 5077 | break; |
| 5078 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5079 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5080 | return false; |
| 5081 | } |
| 5082 | |
| 5083 | return true; |
| 5084 | } |
| 5085 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5086 | bool ValidateGetActiveAttrib(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5087 | GLuint program, |
| 5088 | GLuint index, |
| 5089 | GLsizei bufsize, |
| 5090 | GLsizei *length, |
| 5091 | GLint *size, |
| 5092 | GLenum *type, |
| 5093 | GLchar *name) |
| 5094 | { |
| 5095 | if (bufsize < 0) |
| 5096 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5097 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5098 | return false; |
| 5099 | } |
| 5100 | |
| 5101 | Program *programObject = GetValidProgram(context, program); |
| 5102 | |
| 5103 | if (!programObject) |
| 5104 | { |
| 5105 | return false; |
| 5106 | } |
| 5107 | |
| 5108 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 5109 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5110 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5111 | return false; |
| 5112 | } |
| 5113 | |
| 5114 | return true; |
| 5115 | } |
| 5116 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5117 | bool ValidateGetActiveUniform(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5118 | GLuint program, |
| 5119 | GLuint index, |
| 5120 | GLsizei bufsize, |
| 5121 | GLsizei *length, |
| 5122 | GLint *size, |
| 5123 | GLenum *type, |
| 5124 | GLchar *name) |
| 5125 | { |
| 5126 | if (bufsize < 0) |
| 5127 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5128 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5129 | return false; |
| 5130 | } |
| 5131 | |
| 5132 | Program *programObject = GetValidProgram(context, program); |
| 5133 | |
| 5134 | if (!programObject) |
| 5135 | { |
| 5136 | return false; |
| 5137 | } |
| 5138 | |
| 5139 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 5140 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5141 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5142 | return false; |
| 5143 | } |
| 5144 | |
| 5145 | return true; |
| 5146 | } |
| 5147 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5148 | bool ValidateGetAttachedShaders(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5149 | GLuint program, |
| 5150 | GLsizei maxcount, |
| 5151 | GLsizei *count, |
| 5152 | GLuint *shaders) |
| 5153 | { |
| 5154 | if (maxcount < 0) |
| 5155 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5156 | context->validationError(GL_INVALID_VALUE, kNegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5157 | return false; |
| 5158 | } |
| 5159 | |
| 5160 | Program *programObject = GetValidProgram(context, program); |
| 5161 | |
| 5162 | if (!programObject) |
| 5163 | { |
| 5164 | return false; |
| 5165 | } |
| 5166 | |
| 5167 | return true; |
| 5168 | } |
| 5169 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5170 | bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5171 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5172 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5173 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5174 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5175 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5176 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5177 | return false; |
| 5178 | } |
| 5179 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5180 | Program *programObject = GetValidProgram(context, program); |
| 5181 | |
| 5182 | if (!programObject) |
| 5183 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5184 | context->validationError(GL_INVALID_OPERATION, kProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5185 | return false; |
| 5186 | } |
| 5187 | |
| 5188 | if (!programObject->isLinked()) |
| 5189 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5190 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5191 | return false; |
| 5192 | } |
| 5193 | |
| 5194 | return true; |
| 5195 | } |
| 5196 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5197 | bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5198 | { |
| 5199 | GLenum nativeType; |
| 5200 | unsigned int numParams = 0; |
| 5201 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5202 | } |
| 5203 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5204 | bool ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5205 | { |
| 5206 | return true; |
| 5207 | } |
| 5208 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5209 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5210 | { |
| 5211 | GLenum nativeType; |
| 5212 | unsigned int numParams = 0; |
| 5213 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5214 | } |
| 5215 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5216 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5217 | { |
| 5218 | GLenum nativeType; |
| 5219 | unsigned int numParams = 0; |
| 5220 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5221 | } |
| 5222 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5223 | bool ValidateGetProgramInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5224 | GLuint program, |
| 5225 | GLsizei bufsize, |
| 5226 | GLsizei *length, |
| 5227 | GLchar *infolog) |
| 5228 | { |
| 5229 | if (bufsize < 0) |
| 5230 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5231 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5232 | return false; |
| 5233 | } |
| 5234 | |
| 5235 | Program *programObject = GetValidProgram(context, program); |
| 5236 | if (!programObject) |
| 5237 | { |
| 5238 | return false; |
| 5239 | } |
| 5240 | |
| 5241 | return true; |
| 5242 | } |
| 5243 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5244 | bool ValidateGetShaderInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5245 | GLuint shader, |
| 5246 | GLsizei bufsize, |
| 5247 | GLsizei *length, |
| 5248 | GLchar *infolog) |
| 5249 | { |
| 5250 | if (bufsize < 0) |
| 5251 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5252 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5253 | return false; |
| 5254 | } |
| 5255 | |
| 5256 | Shader *shaderObject = GetValidShader(context, shader); |
| 5257 | if (!shaderObject) |
| 5258 | { |
| 5259 | return false; |
| 5260 | } |
| 5261 | |
| 5262 | return true; |
| 5263 | } |
| 5264 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5265 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5266 | GLenum shadertype, |
| 5267 | GLenum precisiontype, |
| 5268 | GLint *range, |
| 5269 | GLint *precision) |
| 5270 | { |
| 5271 | switch (shadertype) |
| 5272 | { |
| 5273 | case GL_VERTEX_SHADER: |
| 5274 | case GL_FRAGMENT_SHADER: |
| 5275 | break; |
| 5276 | case GL_COMPUTE_SHADER: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5277 | context->validationError(GL_INVALID_OPERATION, |
| 5278 | "compute shader precision not yet implemented."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5279 | return false; |
| 5280 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5281 | context->validationError(GL_INVALID_ENUM, kInvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5282 | return false; |
| 5283 | } |
| 5284 | |
| 5285 | switch (precisiontype) |
| 5286 | { |
| 5287 | case GL_LOW_FLOAT: |
| 5288 | case GL_MEDIUM_FLOAT: |
| 5289 | case GL_HIGH_FLOAT: |
| 5290 | case GL_LOW_INT: |
| 5291 | case GL_MEDIUM_INT: |
| 5292 | case GL_HIGH_INT: |
| 5293 | break; |
| 5294 | |
| 5295 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5296 | context->validationError(GL_INVALID_ENUM, kInvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5297 | return false; |
| 5298 | } |
| 5299 | |
| 5300 | return true; |
| 5301 | } |
| 5302 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5303 | bool ValidateGetShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5304 | GLuint shader, |
| 5305 | GLsizei bufsize, |
| 5306 | GLsizei *length, |
| 5307 | GLchar *source) |
| 5308 | { |
| 5309 | if (bufsize < 0) |
| 5310 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5311 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5312 | return false; |
| 5313 | } |
| 5314 | |
| 5315 | Shader *shaderObject = GetValidShader(context, shader); |
| 5316 | if (!shaderObject) |
| 5317 | { |
| 5318 | return false; |
| 5319 | } |
| 5320 | |
| 5321 | return true; |
| 5322 | } |
| 5323 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5324 | bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5325 | { |
| 5326 | if (strstr(name, "gl_") == name) |
| 5327 | { |
| 5328 | return false; |
| 5329 | } |
| 5330 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5331 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5332 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5333 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5334 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5335 | context->validationError(GL_INVALID_VALUE, kInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5336 | return false; |
| 5337 | } |
| 5338 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5339 | Program *programObject = GetValidProgram(context, program); |
| 5340 | |
| 5341 | if (!programObject) |
| 5342 | { |
| 5343 | return false; |
| 5344 | } |
| 5345 | |
| 5346 | if (!programObject->isLinked()) |
| 5347 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5348 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5349 | return false; |
| 5350 | } |
| 5351 | |
| 5352 | return true; |
| 5353 | } |
| 5354 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5355 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5356 | { |
| 5357 | switch (mode) |
| 5358 | { |
| 5359 | case GL_FASTEST: |
| 5360 | case GL_NICEST: |
| 5361 | case GL_DONT_CARE: |
| 5362 | break; |
| 5363 | |
| 5364 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5365 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5366 | return false; |
| 5367 | } |
| 5368 | |
| 5369 | switch (target) |
| 5370 | { |
| 5371 | case GL_GENERATE_MIPMAP_HINT: |
| 5372 | break; |
| 5373 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5374 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5375 | if (context->getClientVersion() < ES_3_0 && |
| 5376 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5377 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5378 | context->validationError(GL_INVALID_ENUM, |
| 5379 | "hint requires OES_standard_derivatives."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5380 | return false; |
| 5381 | } |
| 5382 | break; |
| 5383 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5384 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5385 | case GL_POINT_SMOOTH_HINT: |
| 5386 | case GL_LINE_SMOOTH_HINT: |
| 5387 | case GL_FOG_HINT: |
| 5388 | if (context->getClientMajorVersion() >= 2) |
| 5389 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5390 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5391 | return false; |
| 5392 | } |
| 5393 | break; |
| 5394 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5395 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5396 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5397 | return false; |
| 5398 | } |
| 5399 | |
| 5400 | return true; |
| 5401 | } |
| 5402 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5403 | bool ValidateIsBuffer(Context *context, GLuint buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5404 | { |
| 5405 | return true; |
| 5406 | } |
| 5407 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5408 | bool ValidateIsFramebuffer(Context *context, GLuint framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5409 | { |
| 5410 | return true; |
| 5411 | } |
| 5412 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5413 | bool ValidateIsProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5414 | { |
| 5415 | return true; |
| 5416 | } |
| 5417 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5418 | bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5419 | { |
| 5420 | return true; |
| 5421 | } |
| 5422 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5423 | bool ValidateIsShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5424 | { |
| 5425 | return true; |
| 5426 | } |
| 5427 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5428 | bool ValidateIsTexture(Context *context, GLuint texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5429 | { |
| 5430 | return true; |
| 5431 | } |
| 5432 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5433 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5434 | { |
| 5435 | if (context->getClientMajorVersion() < 3) |
| 5436 | { |
| 5437 | switch (pname) |
| 5438 | { |
| 5439 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5440 | case GL_UNPACK_SKIP_IMAGES: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5441 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5442 | return false; |
| 5443 | |
| 5444 | case GL_UNPACK_ROW_LENGTH: |
| 5445 | case GL_UNPACK_SKIP_ROWS: |
| 5446 | case GL_UNPACK_SKIP_PIXELS: |
| 5447 | if (!context->getExtensions().unpackSubimage) |
| 5448 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5449 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5450 | return false; |
| 5451 | } |
| 5452 | break; |
| 5453 | |
| 5454 | case GL_PACK_ROW_LENGTH: |
| 5455 | case GL_PACK_SKIP_ROWS: |
| 5456 | case GL_PACK_SKIP_PIXELS: |
| 5457 | if (!context->getExtensions().packSubimage) |
| 5458 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5459 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5460 | return false; |
| 5461 | } |
| 5462 | break; |
| 5463 | } |
| 5464 | } |
| 5465 | |
| 5466 | if (param < 0) |
| 5467 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5468 | context->validationError(GL_INVALID_VALUE, "Cannot use negative values in PixelStorei"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5469 | return false; |
| 5470 | } |
| 5471 | |
| 5472 | switch (pname) |
| 5473 | { |
| 5474 | case GL_UNPACK_ALIGNMENT: |
| 5475 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5476 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5477 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5478 | return false; |
| 5479 | } |
| 5480 | break; |
| 5481 | |
| 5482 | case GL_PACK_ALIGNMENT: |
| 5483 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5484 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5485 | context->validationError(GL_INVALID_VALUE, kInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5486 | return false; |
| 5487 | } |
| 5488 | break; |
| 5489 | |
| 5490 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5491 | if (!context->getExtensions().packReverseRowOrder) |
| 5492 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5493 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5494 | } |
| 5495 | break; |
| 5496 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5497 | case GL_UNPACK_ROW_LENGTH: |
| 5498 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5499 | case GL_UNPACK_SKIP_IMAGES: |
| 5500 | case GL_UNPACK_SKIP_ROWS: |
| 5501 | case GL_UNPACK_SKIP_PIXELS: |
| 5502 | case GL_PACK_ROW_LENGTH: |
| 5503 | case GL_PACK_SKIP_ROWS: |
| 5504 | case GL_PACK_SKIP_PIXELS: |
| 5505 | break; |
| 5506 | |
| 5507 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5508 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5509 | return false; |
| 5510 | } |
| 5511 | |
| 5512 | return true; |
| 5513 | } |
| 5514 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5515 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5516 | { |
| 5517 | return true; |
| 5518 | } |
| 5519 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5520 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5521 | { |
| 5522 | return true; |
| 5523 | } |
| 5524 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5525 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5526 | { |
| 5527 | return true; |
| 5528 | } |
| 5529 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5530 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5531 | { |
| 5532 | if (width < 0 || height < 0) |
| 5533 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5534 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5535 | return false; |
| 5536 | } |
| 5537 | |
| 5538 | return true; |
| 5539 | } |
| 5540 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5541 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5542 | GLsizei n, |
| 5543 | const GLuint *shaders, |
| 5544 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5545 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5546 | GLsizei length) |
| 5547 | { |
| 5548 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5549 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5550 | shaderBinaryFormats.end()) |
| 5551 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5552 | context->validationError(GL_INVALID_ENUM, "Invalid shader binary format."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5553 | return false; |
| 5554 | } |
| 5555 | |
| 5556 | return true; |
| 5557 | } |
| 5558 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5559 | bool ValidateShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5560 | GLuint shader, |
| 5561 | GLsizei count, |
| 5562 | const GLchar *const *string, |
| 5563 | const GLint *length) |
| 5564 | { |
| 5565 | if (count < 0) |
| 5566 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5567 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5568 | return false; |
| 5569 | } |
| 5570 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5571 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5572 | // shader-related entry points |
| 5573 | if (context->getExtensions().webglCompatibility) |
| 5574 | { |
| 5575 | for (GLsizei i = 0; i < count; i++) |
| 5576 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5577 | size_t len = |
| 5578 | (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] | 5579 | |
| 5580 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5581 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5582 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5583 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5584 | context->validationError(GL_INVALID_VALUE, kShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5585 | return false; |
| 5586 | } |
| 5587 | } |
| 5588 | } |
| 5589 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5590 | Shader *shaderObject = GetValidShader(context, shader); |
| 5591 | if (!shaderObject) |
| 5592 | { |
| 5593 | return false; |
| 5594 | } |
| 5595 | |
| 5596 | return true; |
| 5597 | } |
| 5598 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5599 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5600 | { |
| 5601 | if (!IsValidStencilFunc(func)) |
| 5602 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5603 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5604 | return false; |
| 5605 | } |
| 5606 | |
| 5607 | return true; |
| 5608 | } |
| 5609 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5610 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5611 | { |
| 5612 | if (!IsValidStencilFace(face)) |
| 5613 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5614 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5615 | return false; |
| 5616 | } |
| 5617 | |
| 5618 | if (!IsValidStencilFunc(func)) |
| 5619 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5620 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5621 | return false; |
| 5622 | } |
| 5623 | |
| 5624 | return true; |
| 5625 | } |
| 5626 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5627 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5628 | { |
| 5629 | return true; |
| 5630 | } |
| 5631 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5632 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5633 | { |
| 5634 | if (!IsValidStencilFace(face)) |
| 5635 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5636 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5637 | return false; |
| 5638 | } |
| 5639 | |
| 5640 | return true; |
| 5641 | } |
| 5642 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5643 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5644 | { |
| 5645 | if (!IsValidStencilOp(fail)) |
| 5646 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5647 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5648 | return false; |
| 5649 | } |
| 5650 | |
| 5651 | if (!IsValidStencilOp(zfail)) |
| 5652 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5653 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5654 | return false; |
| 5655 | } |
| 5656 | |
| 5657 | if (!IsValidStencilOp(zpass)) |
| 5658 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5659 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5660 | return false; |
| 5661 | } |
| 5662 | |
| 5663 | return true; |
| 5664 | } |
| 5665 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5666 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5667 | GLenum face, |
| 5668 | GLenum fail, |
| 5669 | GLenum zfail, |
| 5670 | GLenum zpass) |
| 5671 | { |
| 5672 | if (!IsValidStencilFace(face)) |
| 5673 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5674 | context->validationError(GL_INVALID_ENUM, kInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5675 | return false; |
| 5676 | } |
| 5677 | |
| 5678 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5679 | } |
| 5680 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5681 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5682 | { |
| 5683 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5684 | } |
| 5685 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5686 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5687 | { |
| 5688 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5689 | } |
| 5690 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5691 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5692 | { |
| 5693 | return ValidateUniform1iv(context, location, 1, &x); |
| 5694 | } |
| 5695 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5696 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5697 | { |
| 5698 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 5699 | } |
| 5700 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5701 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5702 | { |
| 5703 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 5704 | } |
| 5705 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5706 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5707 | { |
| 5708 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 5709 | } |
| 5710 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5711 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5712 | { |
| 5713 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 5714 | } |
| 5715 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5716 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5717 | { |
| 5718 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 5719 | } |
| 5720 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5721 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5722 | { |
| 5723 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 5724 | } |
| 5725 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5726 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5727 | { |
| 5728 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 5729 | } |
| 5730 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5731 | 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] | 5732 | { |
| 5733 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 5734 | } |
| 5735 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5736 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5737 | { |
| 5738 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 5739 | } |
| 5740 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5741 | 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] | 5742 | { |
| 5743 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 5744 | } |
| 5745 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5746 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5747 | { |
| 5748 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 5749 | } |
| 5750 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5751 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5752 | GLint location, |
| 5753 | GLsizei count, |
| 5754 | GLboolean transpose, |
| 5755 | const GLfloat *value) |
| 5756 | { |
| 5757 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 5758 | } |
| 5759 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5760 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5761 | GLint location, |
| 5762 | GLsizei count, |
| 5763 | GLboolean transpose, |
| 5764 | const GLfloat *value) |
| 5765 | { |
| 5766 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 5767 | } |
| 5768 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5769 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5770 | GLint location, |
| 5771 | GLsizei count, |
| 5772 | GLboolean transpose, |
| 5773 | const GLfloat *value) |
| 5774 | { |
| 5775 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 5776 | } |
| 5777 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5778 | bool ValidateValidateProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5779 | { |
| 5780 | Program *programObject = GetValidProgram(context, program); |
| 5781 | |
| 5782 | if (!programObject) |
| 5783 | { |
| 5784 | return false; |
| 5785 | } |
| 5786 | |
| 5787 | return true; |
| 5788 | } |
| 5789 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5790 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5791 | { |
| 5792 | return ValidateVertexAttribIndex(context, index); |
| 5793 | } |
| 5794 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5795 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5796 | { |
| 5797 | return ValidateVertexAttribIndex(context, index); |
| 5798 | } |
| 5799 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5800 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5801 | { |
| 5802 | return ValidateVertexAttribIndex(context, index); |
| 5803 | } |
| 5804 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5805 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5806 | { |
| 5807 | return ValidateVertexAttribIndex(context, index); |
| 5808 | } |
| 5809 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5810 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5811 | { |
| 5812 | return ValidateVertexAttribIndex(context, index); |
| 5813 | } |
| 5814 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5815 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5816 | { |
| 5817 | return ValidateVertexAttribIndex(context, index); |
| 5818 | } |
| 5819 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5820 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5821 | GLuint index, |
| 5822 | GLfloat x, |
| 5823 | GLfloat y, |
| 5824 | GLfloat z, |
| 5825 | GLfloat w) |
| 5826 | { |
| 5827 | return ValidateVertexAttribIndex(context, index); |
| 5828 | } |
| 5829 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5830 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5831 | { |
| 5832 | return ValidateVertexAttribIndex(context, index); |
| 5833 | } |
| 5834 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5835 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5836 | { |
| 5837 | if (width < 0 || height < 0) |
| 5838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5839 | context->validationError(GL_INVALID_VALUE, kViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5840 | return false; |
| 5841 | } |
| 5842 | |
| 5843 | return true; |
| 5844 | } |
| 5845 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5846 | bool ValidateDrawElements(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 5847 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5848 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 5849 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5850 | const void *indices) |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5851 | { |
| 5852 | return ValidateDrawElementsCommon(context, mode, count, type, indices, 1); |
| 5853 | } |
| 5854 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 5855 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5856 | GLenum target, |
| 5857 | GLenum attachment, |
| 5858 | GLenum pname, |
| 5859 | GLint *params) |
| 5860 | { |
| 5861 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 5862 | nullptr); |
| 5863 | } |
| 5864 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5865 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5866 | { |
| 5867 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 5868 | } |
| 5869 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5870 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5871 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5872 | GLint level, |
| 5873 | GLenum internalformat, |
| 5874 | GLint x, |
| 5875 | GLint y, |
| 5876 | GLsizei width, |
| 5877 | GLsizei height, |
| 5878 | GLint border) |
| 5879 | { |
| 5880 | if (context->getClientMajorVersion() < 3) |
| 5881 | { |
| 5882 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 5883 | 0, x, y, width, height, border); |
| 5884 | } |
| 5885 | |
| 5886 | ASSERT(context->getClientMajorVersion() == 3); |
| 5887 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 5888 | 0, x, y, width, height, border); |
| 5889 | } |
| 5890 | |
| 5891 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5892 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5893 | GLint level, |
| 5894 | GLint xoffset, |
| 5895 | GLint yoffset, |
| 5896 | GLint x, |
| 5897 | GLint y, |
| 5898 | GLsizei width, |
| 5899 | GLsizei height) |
| 5900 | { |
| 5901 | if (context->getClientMajorVersion() < 3) |
| 5902 | { |
| 5903 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 5904 | yoffset, x, y, width, height, 0); |
| 5905 | } |
| 5906 | |
| 5907 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 5908 | yoffset, 0, x, y, width, height, 0); |
| 5909 | } |
| 5910 | |
| 5911 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 5912 | { |
| 5913 | return ValidateGenOrDelete(context, n); |
| 5914 | } |
| 5915 | |
| 5916 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 5917 | { |
| 5918 | return ValidateGenOrDelete(context, n); |
| 5919 | } |
| 5920 | |
| 5921 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 5922 | { |
| 5923 | return ValidateGenOrDelete(context, n); |
| 5924 | } |
| 5925 | |
| 5926 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 5927 | { |
| 5928 | return ValidateGenOrDelete(context, n); |
| 5929 | } |
| 5930 | |
| 5931 | bool ValidateDisable(Context *context, GLenum cap) |
| 5932 | { |
| 5933 | if (!ValidCap(context, cap, false)) |
| 5934 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5935 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5936 | return false; |
| 5937 | } |
| 5938 | |
| 5939 | return true; |
| 5940 | } |
| 5941 | |
| 5942 | bool ValidateEnable(Context *context, GLenum cap) |
| 5943 | { |
| 5944 | if (!ValidCap(context, cap, false)) |
| 5945 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5946 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5947 | return false; |
| 5948 | } |
| 5949 | |
| 5950 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 5951 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 5952 | { |
| 5953 | const char *errorMessage = "Current renderer doesn't support alpha-to-coverage"; |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5954 | context->validationError(GL_INVALID_OPERATION, errorMessage); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5955 | |
| 5956 | // We also output an error message to the debugger window if tracing is active, so that |
| 5957 | // developers can see the error message. |
| 5958 | ERR() << errorMessage; |
| 5959 | return false; |
| 5960 | } |
| 5961 | |
| 5962 | return true; |
| 5963 | } |
| 5964 | |
| 5965 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 5966 | GLenum target, |
| 5967 | GLenum attachment, |
| 5968 | GLenum renderbuffertarget, |
| 5969 | GLuint renderbuffer) |
| 5970 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5971 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5972 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5973 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5974 | return false; |
| 5975 | } |
| 5976 | |
| 5977 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0) |
| 5978 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5979 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5980 | return false; |
| 5981 | } |
| 5982 | |
| 5983 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 5984 | renderbuffertarget, renderbuffer); |
| 5985 | } |
| 5986 | |
| 5987 | bool ValidateFramebufferTexture2D(Context *context, |
| 5988 | GLenum target, |
| 5989 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5990 | TextureTarget textarget, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5991 | GLuint texture, |
| 5992 | GLint level) |
| 5993 | { |
| 5994 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 5995 | // extension |
| 5996 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 5997 | level != 0) |
| 5998 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5999 | context->validationError(GL_INVALID_VALUE, kInvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6000 | return false; |
| 6001 | } |
| 6002 | |
| 6003 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6004 | { |
| 6005 | return false; |
| 6006 | } |
| 6007 | |
| 6008 | if (texture != 0) |
| 6009 | { |
| 6010 | gl::Texture *tex = context->getTexture(texture); |
| 6011 | ASSERT(tex); |
| 6012 | |
| 6013 | const gl::Caps &caps = context->getCaps(); |
| 6014 | |
| 6015 | switch (textarget) |
| 6016 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6017 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6018 | { |
| 6019 | if (level > gl::log2(caps.max2DTextureSize)) |
| 6020 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6021 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6022 | return false; |
| 6023 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6024 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6025 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6026 | context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6027 | return false; |
| 6028 | } |
| 6029 | } |
| 6030 | break; |
| 6031 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6032 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6033 | { |
| 6034 | if (level != 0) |
| 6035 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6036 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6037 | return false; |
| 6038 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6039 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6040 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6041 | context->validationError(GL_INVALID_OPERATION, |
| 6042 | "Textarget must match the texture target type."); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6043 | return false; |
| 6044 | } |
| 6045 | } |
| 6046 | break; |
| 6047 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6048 | case TextureTarget::CubeMapNegativeX: |
| 6049 | case TextureTarget::CubeMapNegativeY: |
| 6050 | case TextureTarget::CubeMapNegativeZ: |
| 6051 | case TextureTarget::CubeMapPositiveX: |
| 6052 | case TextureTarget::CubeMapPositiveY: |
| 6053 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6054 | { |
| 6055 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6056 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6057 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6058 | return false; |
| 6059 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6060 | if (tex->getType() != TextureType::CubeMap) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6061 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6062 | context->validationError(GL_INVALID_OPERATION, |
| 6063 | "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6064 | return false; |
| 6065 | } |
| 6066 | } |
| 6067 | break; |
| 6068 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6069 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6070 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6071 | if (context->getClientVersion() < ES_3_1 && |
| 6072 | !context->getExtensions().textureMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6073 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6074 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6075 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6076 | return false; |
| 6077 | } |
| 6078 | |
| 6079 | if (level != 0) |
| 6080 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6081 | context->validationError(GL_INVALID_VALUE, kLevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6082 | return false; |
| 6083 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6084 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6085 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6086 | context->validationError(GL_INVALID_OPERATION, |
| 6087 | "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6088 | return false; |
| 6089 | } |
| 6090 | } |
| 6091 | break; |
| 6092 | |
| 6093 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6094 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6095 | return false; |
| 6096 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | return true; |
| 6100 | } |
| 6101 | |
| 6102 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 6103 | { |
| 6104 | return ValidateGenOrDelete(context, n); |
| 6105 | } |
| 6106 | |
| 6107 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 6108 | { |
| 6109 | return ValidateGenOrDelete(context, n); |
| 6110 | } |
| 6111 | |
| 6112 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 6113 | { |
| 6114 | return ValidateGenOrDelete(context, n); |
| 6115 | } |
| 6116 | |
| 6117 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 6118 | { |
| 6119 | return ValidateGenOrDelete(context, n); |
| 6120 | } |
| 6121 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6122 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6123 | { |
| 6124 | if (!ValidTextureTarget(context, target)) |
| 6125 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6126 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6127 | return false; |
| 6128 | } |
| 6129 | |
| 6130 | Texture *texture = context->getTargetTexture(target); |
| 6131 | |
| 6132 | if (texture == nullptr) |
| 6133 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6134 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6135 | return false; |
| 6136 | } |
| 6137 | |
| 6138 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6139 | |
| 6140 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6141 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6142 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6143 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6144 | context->validationError(GL_INVALID_OPERATION, kBaseLevelOutOfRange); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6145 | return false; |
| 6146 | } |
| 6147 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6148 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6149 | ? TextureTarget::CubeMapPositiveX |
| 6150 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6151 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6152 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6153 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6154 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6155 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6156 | return false; |
| 6157 | } |
| 6158 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6159 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6160 | bool formatUnsized = !format.sized; |
| 6161 | bool formatColorRenderableAndFilterable = |
| 6162 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6163 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6164 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6165 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6166 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6167 | return false; |
| 6168 | } |
| 6169 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6170 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6171 | // generation |
| 6172 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6173 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6174 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6175 | return false; |
| 6176 | } |
| 6177 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6178 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6179 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6180 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6181 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6182 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6183 | return false; |
| 6184 | } |
| 6185 | |
| 6186 | // Non-power of 2 ES2 check |
| 6187 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6188 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6189 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6190 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6191 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6192 | target == TextureType::CubeMap); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6193 | context->validationError(GL_INVALID_OPERATION, kTextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6194 | return false; |
| 6195 | } |
| 6196 | |
| 6197 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6198 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6199 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6200 | context->validationError(GL_INVALID_OPERATION, kCubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6201 | return false; |
| 6202 | } |
| 6203 | |
James Darpinian | 83b2f0e | 2018-11-27 15:56:01 -0800 | [diff] [blame] | 6204 | if (context->getExtensions().webglCompatibility && |
| 6205 | (texture->getWidth(baseTarget, effectiveBaseLevel) == 0 || |
| 6206 | texture->getHeight(baseTarget, effectiveBaseLevel) == 0)) |
| 6207 | { |
| 6208 | context->validationError(GL_INVALID_OPERATION, kGenerateMipmapZeroSize); |
| 6209 | return false; |
| 6210 | } |
| 6211 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6212 | return true; |
| 6213 | } |
| 6214 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6215 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6216 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6217 | GLenum pname, |
| 6218 | GLint *params) |
| 6219 | { |
| 6220 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6221 | } |
| 6222 | |
| 6223 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6224 | GLenum target, |
| 6225 | GLenum pname, |
| 6226 | GLint *params) |
| 6227 | { |
| 6228 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6229 | } |
| 6230 | |
| 6231 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 6232 | { |
| 6233 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6234 | } |
| 6235 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6236 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6237 | { |
| 6238 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6239 | } |
| 6240 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6241 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6242 | { |
| 6243 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6244 | } |
| 6245 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6246 | bool ValidateGetTexParameterIivOES(Context *context, |
| 6247 | TextureType target, |
| 6248 | GLenum pname, |
| 6249 | GLint *params) |
| 6250 | { |
| 6251 | if (context->getClientMajorVersion() < 3) |
| 6252 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6253 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6254 | return false; |
| 6255 | } |
| 6256 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6257 | } |
| 6258 | |
| 6259 | bool ValidateGetTexParameterIuivOES(Context *context, |
| 6260 | TextureType target, |
| 6261 | GLenum pname, |
| 6262 | GLuint *params) |
| 6263 | { |
| 6264 | if (context->getClientMajorVersion() < 3) |
| 6265 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6266 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6267 | return false; |
| 6268 | } |
| 6269 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6270 | } |
| 6271 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6272 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 6273 | { |
| 6274 | return ValidateGetUniformBase(context, program, location); |
| 6275 | } |
| 6276 | |
| 6277 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 6278 | { |
| 6279 | return ValidateGetUniformBase(context, program, location); |
| 6280 | } |
| 6281 | |
| 6282 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6283 | { |
| 6284 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6285 | } |
| 6286 | |
| 6287 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6288 | { |
| 6289 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6290 | } |
| 6291 | |
| 6292 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6293 | { |
| 6294 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6295 | } |
| 6296 | |
| 6297 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6298 | { |
| 6299 | if (!ValidCap(context, cap, true)) |
| 6300 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6301 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6302 | return false; |
| 6303 | } |
| 6304 | |
| 6305 | return true; |
| 6306 | } |
| 6307 | |
| 6308 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 6309 | { |
| 6310 | if (context->hasActiveTransformFeedback(program)) |
| 6311 | { |
| 6312 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6313 | context->validationError(GL_INVALID_OPERATION, |
| 6314 | "Cannot link program while program is " |
| 6315 | "associated with an active transform " |
| 6316 | "feedback object."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6317 | return false; |
| 6318 | } |
| 6319 | |
| 6320 | Program *programObject = GetValidProgram(context, program); |
| 6321 | if (!programObject) |
| 6322 | { |
| 6323 | return false; |
| 6324 | } |
| 6325 | |
| 6326 | return true; |
| 6327 | } |
| 6328 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6329 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6330 | GLint x, |
| 6331 | GLint y, |
| 6332 | GLsizei width, |
| 6333 | GLsizei height, |
| 6334 | GLenum format, |
| 6335 | GLenum type, |
| 6336 | void *pixels) |
| 6337 | { |
| 6338 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6339 | nullptr, pixels); |
| 6340 | } |
| 6341 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6342 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6343 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6344 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6345 | } |
| 6346 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6347 | bool ValidateTexParameterfv(Context *context, |
| 6348 | TextureType target, |
| 6349 | GLenum pname, |
| 6350 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6351 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6352 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6353 | } |
| 6354 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6355 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6356 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6357 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6358 | } |
| 6359 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6360 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6361 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6362 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6363 | } |
| 6364 | |
| 6365 | bool ValidateTexParameterIivOES(Context *context, |
| 6366 | TextureType target, |
| 6367 | GLenum pname, |
| 6368 | const GLint *params) |
| 6369 | { |
| 6370 | if (context->getClientMajorVersion() < 3) |
| 6371 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6372 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6373 | return false; |
| 6374 | } |
| 6375 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6376 | } |
| 6377 | |
| 6378 | bool ValidateTexParameterIuivOES(Context *context, |
| 6379 | TextureType target, |
| 6380 | GLenum pname, |
| 6381 | const GLuint *params) |
| 6382 | { |
| 6383 | if (context->getClientMajorVersion() < 3) |
| 6384 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6385 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6386 | return false; |
| 6387 | } |
| 6388 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6389 | } |
| 6390 | |
| 6391 | bool ValidateUseProgram(Context *context, GLuint program) |
| 6392 | { |
| 6393 | if (program != 0) |
| 6394 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6395 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6396 | if (!programObject) |
| 6397 | { |
| 6398 | // ES 3.1.0 section 7.3 page 72 |
| 6399 | if (context->getShader(program)) |
| 6400 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6401 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6402 | return false; |
| 6403 | } |
| 6404 | else |
| 6405 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6406 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6407 | return false; |
| 6408 | } |
| 6409 | } |
| 6410 | if (!programObject->isLinked()) |
| 6411 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6412 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6413 | return false; |
| 6414 | } |
| 6415 | } |
| 6416 | if (context->getGLState().isTransformFeedbackActiveUnpaused()) |
| 6417 | { |
| 6418 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6419 | context->validationError( |
| 6420 | GL_INVALID_OPERATION, |
| 6421 | "Cannot change active program while transform feedback is unpaused."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6422 | return false; |
| 6423 | } |
| 6424 | |
| 6425 | return true; |
| 6426 | } |
| 6427 | |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6428 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences) |
| 6429 | { |
| 6430 | if (!context->getExtensions().fence) |
| 6431 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6432 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6433 | return false; |
| 6434 | } |
| 6435 | |
| 6436 | if (n < 0) |
| 6437 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6438 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6439 | return false; |
| 6440 | } |
| 6441 | |
| 6442 | return true; |
| 6443 | } |
| 6444 | |
| 6445 | bool ValidateFinishFenceNV(Context *context, GLuint fence) |
| 6446 | { |
| 6447 | if (!context->getExtensions().fence) |
| 6448 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6449 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6450 | return false; |
| 6451 | } |
| 6452 | |
| 6453 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6454 | |
| 6455 | if (fenceObject == nullptr) |
| 6456 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6457 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6458 | return false; |
| 6459 | } |
| 6460 | |
| 6461 | if (!fenceObject->isSet()) |
| 6462 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6463 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6464 | return false; |
| 6465 | } |
| 6466 | |
| 6467 | return true; |
| 6468 | } |
| 6469 | |
| 6470 | bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences) |
| 6471 | { |
| 6472 | if (!context->getExtensions().fence) |
| 6473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6474 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6475 | return false; |
| 6476 | } |
| 6477 | |
| 6478 | if (n < 0) |
| 6479 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6480 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6481 | return false; |
| 6482 | } |
| 6483 | |
| 6484 | return true; |
| 6485 | } |
| 6486 | |
| 6487 | bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params) |
| 6488 | { |
| 6489 | if (!context->getExtensions().fence) |
| 6490 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6491 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6492 | return false; |
| 6493 | } |
| 6494 | |
| 6495 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6496 | |
| 6497 | if (fenceObject == nullptr) |
| 6498 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6499 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6500 | return false; |
| 6501 | } |
| 6502 | |
| 6503 | if (!fenceObject->isSet()) |
| 6504 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6505 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6506 | return false; |
| 6507 | } |
| 6508 | |
| 6509 | switch (pname) |
| 6510 | { |
| 6511 | case GL_FENCE_STATUS_NV: |
| 6512 | case GL_FENCE_CONDITION_NV: |
| 6513 | break; |
| 6514 | |
| 6515 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6516 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6517 | return false; |
| 6518 | } |
| 6519 | |
| 6520 | return true; |
| 6521 | } |
| 6522 | |
| 6523 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6524 | { |
| 6525 | if (!context->getExtensions().robustness) |
| 6526 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6527 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6528 | return false; |
| 6529 | } |
| 6530 | |
| 6531 | return true; |
| 6532 | } |
| 6533 | |
| 6534 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
| 6535 | GLuint shader, |
| 6536 | GLsizei bufsize, |
| 6537 | GLsizei *length, |
| 6538 | GLchar *source) |
| 6539 | { |
| 6540 | if (!context->getExtensions().translatedShaderSource) |
| 6541 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6542 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6543 | return false; |
| 6544 | } |
| 6545 | |
| 6546 | if (bufsize < 0) |
| 6547 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6548 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6549 | return false; |
| 6550 | } |
| 6551 | |
| 6552 | Shader *shaderObject = context->getShader(shader); |
| 6553 | |
| 6554 | if (!shaderObject) |
| 6555 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6556 | context->validationError(GL_INVALID_OPERATION, kInvalidShaderName); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6557 | return false; |
| 6558 | } |
| 6559 | |
| 6560 | return true; |
| 6561 | } |
| 6562 | |
| 6563 | bool ValidateIsFenceNV(Context *context, GLuint fence) |
| 6564 | { |
| 6565 | if (!context->getExtensions().fence) |
| 6566 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6567 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6568 | return false; |
| 6569 | } |
| 6570 | |
| 6571 | return true; |
| 6572 | } |
| 6573 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6574 | bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition) |
| 6575 | { |
| 6576 | if (!context->getExtensions().fence) |
| 6577 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6578 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6579 | return false; |
| 6580 | } |
| 6581 | |
| 6582 | if (condition != GL_ALL_COMPLETED_NV) |
| 6583 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6584 | context->validationError(GL_INVALID_ENUM, kInvalidFenceCondition); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6585 | return false; |
| 6586 | } |
| 6587 | |
| 6588 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6589 | |
| 6590 | if (fenceObject == nullptr) |
| 6591 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6592 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6593 | return false; |
| 6594 | } |
| 6595 | |
| 6596 | return true; |
| 6597 | } |
| 6598 | |
| 6599 | bool ValidateTestFenceNV(Context *context, GLuint fence) |
| 6600 | { |
| 6601 | if (!context->getExtensions().fence) |
| 6602 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6603 | context->validationError(GL_INVALID_OPERATION, kNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6604 | return false; |
| 6605 | } |
| 6606 | |
| 6607 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6608 | |
| 6609 | if (fenceObject == nullptr) |
| 6610 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6611 | context->validationError(GL_INVALID_OPERATION, kInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6612 | return false; |
| 6613 | } |
| 6614 | |
| 6615 | if (fenceObject->isSet() != GL_TRUE) |
| 6616 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6617 | context->validationError(GL_INVALID_OPERATION, kInvalidFenceState); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6618 | return false; |
| 6619 | } |
| 6620 | |
| 6621 | return true; |
| 6622 | } |
| 6623 | |
| 6624 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6625 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6626 | GLsizei levels, |
| 6627 | GLenum internalformat, |
| 6628 | GLsizei width, |
| 6629 | GLsizei height) |
| 6630 | { |
| 6631 | if (!context->getExtensions().textureStorage) |
| 6632 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6633 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6634 | return false; |
| 6635 | } |
| 6636 | |
| 6637 | if (context->getClientMajorVersion() < 3) |
| 6638 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6639 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6640 | height); |
| 6641 | } |
| 6642 | |
| 6643 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6644 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6645 | 1); |
| 6646 | } |
| 6647 | |
| 6648 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 6649 | { |
| 6650 | if (!context->getExtensions().instancedArrays) |
| 6651 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6652 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6653 | return false; |
| 6654 | } |
| 6655 | |
| 6656 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6657 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6658 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6659 | return false; |
| 6660 | } |
| 6661 | |
| 6662 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 6663 | { |
| 6664 | if (index == 0 && divisor != 0) |
| 6665 | { |
| 6666 | const char *errorMessage = |
| 6667 | "The current context doesn't support setting a non-zero divisor on the " |
| 6668 | "attribute with index zero. " |
| 6669 | "Please reorder the attributes in your vertex shader so that attribute zero " |
| 6670 | "can have a zero divisor."; |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6671 | context->validationError(GL_INVALID_OPERATION, errorMessage); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6672 | |
| 6673 | // We also output an error message to the debugger window if tracing is active, so |
| 6674 | // that developers can see the error message. |
| 6675 | ERR() << errorMessage; |
| 6676 | return false; |
| 6677 | } |
| 6678 | } |
| 6679 | |
| 6680 | return true; |
| 6681 | } |
| 6682 | |
| 6683 | bool ValidateTexImage3DOES(Context *context, |
| 6684 | GLenum target, |
| 6685 | GLint level, |
| 6686 | GLenum internalformat, |
| 6687 | GLsizei width, |
| 6688 | GLsizei height, |
| 6689 | GLsizei depth, |
| 6690 | GLint border, |
| 6691 | GLenum format, |
| 6692 | GLenum type, |
| 6693 | const void *pixels) |
| 6694 | { |
| 6695 | UNIMPLEMENTED(); // FIXME |
| 6696 | return false; |
| 6697 | } |
| 6698 | |
| 6699 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 6700 | { |
| 6701 | if (!context->getExtensions().debugMarker) |
| 6702 | { |
| 6703 | // The debug marker calls should not set error state |
| 6704 | // 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] | 6705 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6706 | return false; |
| 6707 | } |
| 6708 | |
| 6709 | return true; |
| 6710 | } |
| 6711 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6712 | bool ValidateTexStorage1DEXT(Context *context, |
| 6713 | GLenum target, |
| 6714 | GLsizei levels, |
| 6715 | GLenum internalformat, |
| 6716 | GLsizei width) |
| 6717 | { |
| 6718 | UNIMPLEMENTED(); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6719 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6720 | return false; |
| 6721 | } |
| 6722 | |
| 6723 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6724 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6725 | GLsizei levels, |
| 6726 | GLenum internalformat, |
| 6727 | GLsizei width, |
| 6728 | GLsizei height, |
| 6729 | GLsizei depth) |
| 6730 | { |
| 6731 | if (!context->getExtensions().textureStorage) |
| 6732 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6733 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6734 | return false; |
| 6735 | } |
| 6736 | |
| 6737 | if (context->getClientMajorVersion() < 3) |
| 6738 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6739 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6740 | return false; |
| 6741 | } |
| 6742 | |
| 6743 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 6744 | depth); |
| 6745 | } |
| 6746 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6747 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 6748 | { |
| 6749 | if (!context->getExtensions().parallelShaderCompile) |
| 6750 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6751 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6752 | return false; |
| 6753 | } |
| 6754 | return true; |
| 6755 | } |
| 6756 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6757 | bool ValidateMultiDrawArraysANGLE(Context *context, |
| 6758 | PrimitiveMode mode, |
| 6759 | const GLint *firsts, |
| 6760 | const GLsizei *counts, |
| 6761 | GLsizei drawcount) |
| 6762 | { |
| 6763 | if (!context->getExtensions().multiDraw) |
| 6764 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6765 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6766 | return false; |
| 6767 | } |
| 6768 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6769 | { |
| 6770 | if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID])) |
| 6771 | { |
| 6772 | return false; |
| 6773 | } |
| 6774 | } |
| 6775 | return true; |
| 6776 | } |
| 6777 | |
| 6778 | bool ValidateMultiDrawElementsANGLE(Context *context, |
| 6779 | PrimitiveMode mode, |
| 6780 | const GLsizei *counts, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 6781 | DrawElementsType type, |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 6782 | const GLvoid *const *indices, |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6783 | GLsizei drawcount) |
| 6784 | { |
| 6785 | if (!context->getExtensions().multiDraw) |
| 6786 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6787 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6788 | return false; |
| 6789 | } |
| 6790 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6791 | { |
Austin Eng | 3b7c9d0 | 2018-11-21 18:09:05 -0800 | [diff] [blame] | 6792 | if (!ValidateDrawElements(context, mode, counts[drawID], type, indices[drawID])) |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6793 | { |
| 6794 | return false; |
| 6795 | } |
| 6796 | } |
| 6797 | return true; |
| 6798 | } |
| 6799 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6800 | } // namespace gl |