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 | { |
| 33 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 34 | namespace |
| 35 | { |
| 36 | |
| 37 | bool IsPartialBlit(gl::Context *context, |
| 38 | const FramebufferAttachment *readBuffer, |
| 39 | const FramebufferAttachment *writeBuffer, |
| 40 | GLint srcX0, |
| 41 | GLint srcY0, |
| 42 | GLint srcX1, |
| 43 | GLint srcY1, |
| 44 | GLint dstX0, |
| 45 | GLint dstY0, |
| 46 | GLint dstX1, |
| 47 | GLint dstY1) |
| 48 | { |
| 49 | const Extents &writeSize = writeBuffer->getSize(); |
| 50 | const Extents &readSize = readBuffer->getSize(); |
| 51 | |
| 52 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width || |
| 53 | dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height) |
| 54 | { |
| 55 | return true; |
| 56 | } |
| 57 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 58 | if (context->getGLState().isScissorTestEnabled()) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 59 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 60 | const Rectangle &scissor = context->getGLState().getScissor(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 61 | return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width || |
| 62 | scissor.height < writeSize.height; |
| 63 | } |
| 64 | |
| 65 | return false; |
| 66 | } |
| 67 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 68 | template <typename T> |
| 69 | bool ValidatePathInstances(gl::Context *context, |
| 70 | GLsizei numPaths, |
| 71 | const void *paths, |
| 72 | GLuint pathBase) |
| 73 | { |
| 74 | const auto *array = static_cast<const T *>(paths); |
| 75 | |
| 76 | for (GLsizei i = 0; i < numPaths; ++i) |
| 77 | { |
| 78 | const GLuint pathName = array[i] + pathBase; |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 79 | if (context->isPathGenerated(pathName) && !context->isPath(pathName)) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 80 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 81 | context->validationError(GL_INVALID_OPERATION, kErrorNoSuchPath); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 82 | return false; |
| 83 | } |
| 84 | } |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | bool ValidateInstancedPathParameters(gl::Context *context, |
| 89 | GLsizei numPaths, |
| 90 | GLenum pathNameType, |
| 91 | const void *paths, |
| 92 | GLuint pathBase, |
| 93 | GLenum transformType, |
| 94 | const GLfloat *transformValues) |
| 95 | { |
| 96 | if (!context->getExtensions().pathRendering) |
| 97 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 98 | context->validationError(GL_INVALID_OPERATION, |
| 99 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | if (paths == nullptr) |
| 104 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 105 | context->validationError(GL_INVALID_VALUE, "No path name array."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 106 | return false; |
| 107 | } |
| 108 | |
| 109 | if (numPaths < 0) |
| 110 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 111 | context->validationError(GL_INVALID_VALUE, "Invalid (negative) numPaths."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 112 | return false; |
| 113 | } |
| 114 | |
| 115 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(numPaths)) |
| 116 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 117 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 118 | return false; |
| 119 | } |
| 120 | |
| 121 | std::uint32_t pathNameTypeSize = 0; |
| 122 | std::uint32_t componentCount = 0; |
| 123 | |
| 124 | switch (pathNameType) |
| 125 | { |
| 126 | case GL_UNSIGNED_BYTE: |
| 127 | pathNameTypeSize = sizeof(GLubyte); |
| 128 | if (!ValidatePathInstances<GLubyte>(context, numPaths, paths, pathBase)) |
| 129 | return false; |
| 130 | break; |
| 131 | |
| 132 | case GL_BYTE: |
| 133 | pathNameTypeSize = sizeof(GLbyte); |
| 134 | if (!ValidatePathInstances<GLbyte>(context, numPaths, paths, pathBase)) |
| 135 | return false; |
| 136 | break; |
| 137 | |
| 138 | case GL_UNSIGNED_SHORT: |
| 139 | pathNameTypeSize = sizeof(GLushort); |
| 140 | if (!ValidatePathInstances<GLushort>(context, numPaths, paths, pathBase)) |
| 141 | return false; |
| 142 | break; |
| 143 | |
| 144 | case GL_SHORT: |
| 145 | pathNameTypeSize = sizeof(GLshort); |
| 146 | if (!ValidatePathInstances<GLshort>(context, numPaths, paths, pathBase)) |
| 147 | return false; |
| 148 | break; |
| 149 | |
| 150 | case GL_UNSIGNED_INT: |
| 151 | pathNameTypeSize = sizeof(GLuint); |
| 152 | if (!ValidatePathInstances<GLuint>(context, numPaths, paths, pathBase)) |
| 153 | return false; |
| 154 | break; |
| 155 | |
| 156 | case GL_INT: |
| 157 | pathNameTypeSize = sizeof(GLint); |
| 158 | if (!ValidatePathInstances<GLint>(context, numPaths, paths, pathBase)) |
| 159 | return false; |
| 160 | break; |
| 161 | |
| 162 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 163 | context->validationError(GL_INVALID_ENUM, "Invalid path name type."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 164 | return false; |
| 165 | } |
| 166 | |
| 167 | switch (transformType) |
| 168 | { |
| 169 | case GL_NONE: |
| 170 | componentCount = 0; |
| 171 | break; |
| 172 | case GL_TRANSLATE_X_CHROMIUM: |
| 173 | case GL_TRANSLATE_Y_CHROMIUM: |
| 174 | componentCount = 1; |
| 175 | break; |
| 176 | case GL_TRANSLATE_2D_CHROMIUM: |
| 177 | componentCount = 2; |
| 178 | break; |
| 179 | case GL_TRANSLATE_3D_CHROMIUM: |
| 180 | componentCount = 3; |
| 181 | break; |
| 182 | case GL_AFFINE_2D_CHROMIUM: |
| 183 | case GL_TRANSPOSE_AFFINE_2D_CHROMIUM: |
| 184 | componentCount = 6; |
| 185 | break; |
| 186 | case GL_AFFINE_3D_CHROMIUM: |
| 187 | case GL_TRANSPOSE_AFFINE_3D_CHROMIUM: |
| 188 | componentCount = 12; |
| 189 | break; |
| 190 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 191 | context->validationError(GL_INVALID_ENUM, "Invalid transformation."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 192 | return false; |
| 193 | } |
| 194 | if (componentCount != 0 && transformValues == nullptr) |
| 195 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 196 | context->validationError(GL_INVALID_VALUE, "No transform array given."); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 197 | return false; |
| 198 | } |
| 199 | |
| 200 | angle::CheckedNumeric<std::uint32_t> checkedSize(0); |
| 201 | checkedSize += (numPaths * pathNameTypeSize); |
| 202 | checkedSize += (numPaths * sizeof(GLfloat) * componentCount); |
| 203 | if (!checkedSize.IsValid()) |
| 204 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 205 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 206 | return false; |
| 207 | } |
| 208 | |
| 209 | return true; |
| 210 | } |
| 211 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 212 | bool IsValidCopyTextureSourceInternalFormatEnum(GLenum internalFormat) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 213 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 214 | // Table 1.1 from the CHROMIUM_copy_texture spec |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 215 | switch (GetUnsizedFormat(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 216 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 217 | case GL_RED: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 218 | case GL_ALPHA: |
| 219 | case GL_LUMINANCE: |
| 220 | case GL_LUMINANCE_ALPHA: |
| 221 | case GL_RGB: |
| 222 | case GL_RGBA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 223 | case GL_RGB8: |
| 224 | case GL_RGBA8: |
| 225 | case GL_BGRA_EXT: |
| 226 | case GL_BGRA8_EXT: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 227 | return true; |
| 228 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 229 | default: |
| 230 | return false; |
| 231 | } |
| 232 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 233 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 234 | bool IsValidCopySubTextureSourceInternalFormat(GLenum internalFormat) |
| 235 | { |
| 236 | return IsValidCopyTextureSourceInternalFormatEnum(internalFormat); |
| 237 | } |
| 238 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 239 | bool IsValidCopyTextureDestinationInternalFormatEnum(GLint internalFormat) |
| 240 | { |
| 241 | // Table 1.0 from the CHROMIUM_copy_texture spec |
| 242 | switch (internalFormat) |
| 243 | { |
| 244 | case GL_RGB: |
| 245 | case GL_RGBA: |
| 246 | case GL_RGB8: |
| 247 | case GL_RGBA8: |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 248 | case GL_BGRA_EXT: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 249 | case GL_BGRA8_EXT: |
| 250 | case GL_SRGB_EXT: |
| 251 | case GL_SRGB_ALPHA_EXT: |
| 252 | case GL_R8: |
| 253 | case GL_R8UI: |
| 254 | case GL_RG8: |
| 255 | case GL_RG8UI: |
| 256 | case GL_SRGB8: |
| 257 | case GL_RGB565: |
| 258 | case GL_RGB8UI: |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 259 | case GL_RGB10_A2: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 260 | case GL_SRGB8_ALPHA8: |
| 261 | case GL_RGB5_A1: |
| 262 | case GL_RGBA4: |
| 263 | case GL_RGBA8UI: |
| 264 | case GL_RGB9_E5: |
| 265 | case GL_R16F: |
| 266 | case GL_R32F: |
| 267 | case GL_RG16F: |
| 268 | case GL_RG32F: |
| 269 | case GL_RGB16F: |
| 270 | case GL_RGB32F: |
| 271 | case GL_RGBA16F: |
| 272 | case GL_RGBA32F: |
| 273 | case GL_R11F_G11F_B10F: |
Brandon Jones | 340b7b8 | 2017-06-26 13:02:31 -0700 | [diff] [blame] | 274 | case GL_LUMINANCE: |
| 275 | case GL_LUMINANCE_ALPHA: |
| 276 | case GL_ALPHA: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 277 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 278 | |
| 279 | default: |
| 280 | return false; |
| 281 | } |
| 282 | } |
| 283 | |
Geoff Lang | 6be3d4c | 2017-06-16 15:54:15 -0400 | [diff] [blame] | 284 | bool IsValidCopySubTextureDestionationInternalFormat(GLenum internalFormat) |
| 285 | { |
| 286 | return IsValidCopyTextureDestinationInternalFormatEnum(internalFormat); |
| 287 | } |
| 288 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 289 | bool IsValidCopyTextureDestinationFormatType(Context *context, GLint internalFormat, GLenum type) |
| 290 | { |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 291 | if (!IsValidCopyTextureDestinationInternalFormatEnum(internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 292 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 293 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 294 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 297 | if (!ValidES3FormatCombination(GetUnsizedFormat(internalFormat), type, internalFormat)) |
| 298 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 299 | context->validationError(GL_INVALID_OPERATION, kErrorMismatchedTypeAndFormat); |
Geoff Lang | c0094ec | 2017-08-16 14:16:24 -0400 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 303 | const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat, type); |
| 304 | if (!internalFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 305 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 306 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 307 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return true; |
| 311 | } |
| 312 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 313 | bool IsValidCopyTextureDestinationTargetEnum(Context *context, TextureTarget target) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 314 | { |
| 315 | switch (target) |
| 316 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 317 | case TextureTarget::_2D: |
| 318 | case TextureTarget::CubeMapNegativeX: |
| 319 | case TextureTarget::CubeMapNegativeY: |
| 320 | case TextureTarget::CubeMapNegativeZ: |
| 321 | case TextureTarget::CubeMapPositiveX: |
| 322 | case TextureTarget::CubeMapPositiveY: |
| 323 | case TextureTarget::CubeMapPositiveZ: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 324 | return true; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 325 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 326 | case TextureTarget::Rectangle: |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 327 | return context->getExtensions().textureRectangle; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 328 | |
| 329 | default: |
| 330 | return false; |
| 331 | } |
| 332 | } |
| 333 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 334 | bool IsValidCopyTextureDestinationTarget(Context *context, |
| 335 | TextureType textureType, |
| 336 | TextureTarget target) |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 337 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 338 | return TextureTargetToType(target) == textureType; |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 341 | bool IsValidCopyTextureSourceTarget(Context *context, TextureType type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 342 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 343 | switch (type) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 344 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 345 | case TextureType::_2D: |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 346 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 347 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 348 | return context->getExtensions().textureRectangle; |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 349 | |
| 350 | // TODO(geofflang): accept GL_TEXTURE_EXTERNAL_OES if the texture_external extension is |
| 351 | // supported |
| 352 | |
| 353 | default: |
| 354 | return false; |
| 355 | } |
| 356 | } |
| 357 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 358 | bool IsValidCopyTextureSourceLevel(Context *context, TextureType type, GLint level) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 359 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 360 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 361 | { |
| 362 | return false; |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 365 | if (level > 0 && context->getClientVersion() < ES_3_0) |
| 366 | { |
| 367 | return false; |
| 368 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 369 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 370 | return true; |
| 371 | } |
| 372 | |
| 373 | bool IsValidCopyTextureDestinationLevel(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 374 | TextureType type, |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 375 | GLint level, |
| 376 | GLsizei width, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 377 | GLsizei height, |
| 378 | bool isSubImage) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 379 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 380 | if (!ValidMipLevel(context, type, level)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 381 | { |
| 382 | return false; |
| 383 | } |
| 384 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 385 | if (!ValidImageSizeParameters(context, type, level, width, height, 1, isSubImage)) |
| 386 | { |
| 387 | return false; |
| 388 | } |
| 389 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 390 | const Caps &caps = context->getCaps(); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 391 | switch (type) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 392 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 393 | case TextureType::_2D: |
| 394 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 395 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
| 396 | case TextureType::Rectangle: |
| 397 | ASSERT(level == 0); |
| 398 | return static_cast<GLuint>(width) <= (caps.max2DTextureSize >> level) && |
| 399 | static_cast<GLuint>(height) <= (caps.max2DTextureSize >> level); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 400 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 401 | case TextureType::CubeMap: |
| 402 | return static_cast<GLuint>(width) <= (caps.maxCubeMapTextureSize >> level) && |
| 403 | static_cast<GLuint>(height) <= (caps.maxCubeMapTextureSize >> level); |
| 404 | default: |
| 405 | return true; |
| 406 | } |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 409 | bool IsValidStencilFunc(GLenum func) |
| 410 | { |
| 411 | switch (func) |
| 412 | { |
| 413 | case GL_NEVER: |
| 414 | case GL_ALWAYS: |
| 415 | case GL_LESS: |
| 416 | case GL_LEQUAL: |
| 417 | case GL_EQUAL: |
| 418 | case GL_GEQUAL: |
| 419 | case GL_GREATER: |
| 420 | case GL_NOTEQUAL: |
| 421 | return true; |
| 422 | |
| 423 | default: |
| 424 | return false; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | bool IsValidStencilFace(GLenum face) |
| 429 | { |
| 430 | switch (face) |
| 431 | { |
| 432 | case GL_FRONT: |
| 433 | case GL_BACK: |
| 434 | case GL_FRONT_AND_BACK: |
| 435 | return true; |
| 436 | |
| 437 | default: |
| 438 | return false; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | bool IsValidStencilOp(GLenum op) |
| 443 | { |
| 444 | switch (op) |
| 445 | { |
| 446 | case GL_ZERO: |
| 447 | case GL_KEEP: |
| 448 | case GL_REPLACE: |
| 449 | case GL_INCR: |
| 450 | case GL_DECR: |
| 451 | case GL_INVERT: |
| 452 | case GL_INCR_WRAP: |
| 453 | case GL_DECR_WRAP: |
| 454 | return true; |
| 455 | |
| 456 | default: |
| 457 | return false; |
| 458 | } |
| 459 | } |
| 460 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 461 | bool ValidateES2CopyTexImageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 462 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 463 | GLint level, |
| 464 | GLenum internalformat, |
| 465 | bool isSubImage, |
| 466 | GLint xoffset, |
| 467 | GLint yoffset, |
| 468 | GLint x, |
| 469 | GLint y, |
| 470 | GLsizei width, |
| 471 | GLsizei height, |
| 472 | GLint border) |
| 473 | { |
| 474 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 475 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 476 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 477 | return false; |
| 478 | } |
| 479 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 480 | TextureType texType = TextureTargetToType(target); |
| 481 | if (!ValidImageSizeParameters(context, texType, level, width, height, 1, isSubImage)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 482 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 483 | context->validationError(GL_INVALID_VALUE, "Invalid texture dimensions."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 484 | return false; |
| 485 | } |
| 486 | |
| 487 | Format textureFormat = Format::Invalid(); |
| 488 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 489 | xoffset, yoffset, 0, x, y, width, height, border, |
| 490 | &textureFormat)) |
| 491 | { |
| 492 | return false; |
| 493 | } |
| 494 | |
| 495 | const gl::Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
| 496 | GLenum colorbufferFormat = |
| 497 | framebuffer->getReadColorbuffer()->getFormat().info->sizedInternalFormat; |
| 498 | const auto &formatInfo = *textureFormat.info; |
| 499 | |
| 500 | // [OpenGL ES 2.0.24] table 3.9 |
| 501 | if (isSubImage) |
| 502 | { |
| 503 | switch (formatInfo.format) |
| 504 | { |
| 505 | case GL_ALPHA: |
| 506 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 507 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 508 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 509 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 510 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 511 | return false; |
| 512 | } |
| 513 | break; |
| 514 | case GL_LUMINANCE: |
| 515 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 516 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 517 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 518 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGRA8_EXT && |
| 519 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 520 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 521 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 522 | return false; |
| 523 | } |
| 524 | break; |
| 525 | case GL_RED_EXT: |
| 526 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 527 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 528 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 529 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_R32F && |
| 530 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 531 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 532 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 533 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 534 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 535 | return false; |
| 536 | } |
| 537 | break; |
| 538 | case GL_RG_EXT: |
| 539 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 540 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 541 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_RGBA8_OES && |
| 542 | colorbufferFormat != GL_RG32F && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 543 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 544 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 545 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 546 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 547 | return false; |
| 548 | } |
| 549 | break; |
| 550 | case GL_RGB: |
| 551 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 552 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 553 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGB32F && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 554 | colorbufferFormat != GL_RGBA32F && colorbufferFormat != GL_BGRA8_EXT && |
| 555 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 556 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 557 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 558 | return false; |
| 559 | } |
| 560 | break; |
| 561 | case GL_LUMINANCE_ALPHA: |
| 562 | case GL_RGBA: |
| 563 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
Geoff Lang | 0c09e26 | 2017-05-03 09:43:13 -0400 | [diff] [blame] | 564 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_RGBA32F && |
| 565 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 566 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 567 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 568 | return false; |
| 569 | } |
| 570 | break; |
| 571 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 572 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 573 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 574 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 575 | case GL_ETC1_RGB8_OES: |
| 576 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 577 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 578 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 579 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 580 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 581 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 582 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 583 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 584 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 585 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 586 | return false; |
| 587 | case GL_DEPTH_COMPONENT: |
| 588 | case GL_DEPTH_STENCIL_OES: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 589 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 590 | return false; |
| 591 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 592 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 593 | return false; |
| 594 | } |
| 595 | |
| 596 | if (formatInfo.type == GL_FLOAT && !context->getExtensions().textureFloat) |
| 597 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 598 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 599 | return false; |
| 600 | } |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | switch (internalformat) |
| 605 | { |
| 606 | case GL_ALPHA: |
| 607 | if (colorbufferFormat != GL_ALPHA8_EXT && colorbufferFormat != GL_RGBA4 && |
| 608 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 609 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 610 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 611 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 612 | return false; |
| 613 | } |
| 614 | break; |
| 615 | case GL_LUMINANCE: |
| 616 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 617 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 618 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 619 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 620 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 621 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 622 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 623 | return false; |
| 624 | } |
| 625 | break; |
| 626 | case GL_RED_EXT: |
| 627 | if (colorbufferFormat != GL_R8_EXT && colorbufferFormat != GL_RG8_EXT && |
| 628 | colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 629 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 630 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 631 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 632 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 633 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 634 | return false; |
| 635 | } |
| 636 | break; |
| 637 | case GL_RG_EXT: |
| 638 | if (colorbufferFormat != GL_RG8_EXT && colorbufferFormat != GL_RGB565 && |
| 639 | colorbufferFormat != GL_RGB8_OES && colorbufferFormat != GL_RGBA4 && |
| 640 | colorbufferFormat != GL_RGB5_A1 && colorbufferFormat != GL_BGRA8_EXT && |
| 641 | colorbufferFormat != GL_RGBA8_OES && colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 642 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 643 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 644 | return false; |
| 645 | } |
| 646 | break; |
| 647 | case GL_RGB: |
| 648 | if (colorbufferFormat != GL_RGB565 && colorbufferFormat != GL_RGB8_OES && |
| 649 | colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 650 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 651 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 652 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 653 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 654 | return false; |
| 655 | } |
| 656 | break; |
| 657 | case GL_LUMINANCE_ALPHA: |
| 658 | case GL_RGBA: |
| 659 | if (colorbufferFormat != GL_RGBA4 && colorbufferFormat != GL_RGB5_A1 && |
| 660 | colorbufferFormat != GL_BGRA8_EXT && colorbufferFormat != GL_RGBA8_OES && |
| 661 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
| 662 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 663 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 664 | return false; |
| 665 | } |
| 666 | break; |
| 667 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 668 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 669 | if (context->getExtensions().textureCompressionDXT1) |
| 670 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 671 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 672 | return false; |
| 673 | } |
| 674 | else |
| 675 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 676 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 677 | return false; |
| 678 | } |
| 679 | break; |
| 680 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 681 | if (context->getExtensions().textureCompressionDXT3) |
| 682 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 683 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 684 | return false; |
| 685 | } |
| 686 | else |
| 687 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 688 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 689 | return false; |
| 690 | } |
| 691 | break; |
| 692 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 693 | if (context->getExtensions().textureCompressionDXT5) |
| 694 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 695 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 696 | return false; |
| 697 | } |
| 698 | else |
| 699 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 700 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 701 | return false; |
| 702 | } |
| 703 | break; |
| 704 | case GL_ETC1_RGB8_OES: |
| 705 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 706 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 707 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 708 | return false; |
| 709 | } |
| 710 | else |
| 711 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 712 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 713 | return false; |
| 714 | } |
| 715 | break; |
| 716 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 717 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 718 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 719 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 720 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 721 | if (context->getExtensions().lossyETCDecode) |
| 722 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 723 | context->validationError(GL_INVALID_OPERATION, |
| 724 | "ETC lossy decode formats can't be copied to."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 725 | return false; |
| 726 | } |
| 727 | else |
| 728 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 729 | context->validationError(GL_INVALID_ENUM, |
| 730 | "ANGLE_lossy_etc_decode extension is not supported."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 731 | return false; |
| 732 | } |
| 733 | break; |
| 734 | case GL_DEPTH_COMPONENT: |
| 735 | case GL_DEPTH_COMPONENT16: |
| 736 | case GL_DEPTH_COMPONENT32_OES: |
| 737 | case GL_DEPTH_STENCIL_OES: |
| 738 | case GL_DEPTH24_STENCIL8_OES: |
| 739 | if (context->getExtensions().depthTextures) |
| 740 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 741 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 742 | return false; |
| 743 | } |
| 744 | else |
| 745 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 746 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 747 | return false; |
| 748 | } |
| 749 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 750 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 751 | return false; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 756 | return (width > 0 && height > 0); |
| 757 | } |
| 758 | |
| 759 | bool ValidCap(const Context *context, GLenum cap, bool queryOnly) |
| 760 | { |
| 761 | switch (cap) |
| 762 | { |
| 763 | // EXT_multisample_compatibility |
| 764 | case GL_MULTISAMPLE_EXT: |
| 765 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 766 | return context->getExtensions().multisampleCompatibility; |
| 767 | |
| 768 | case GL_CULL_FACE: |
| 769 | case GL_POLYGON_OFFSET_FILL: |
| 770 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 771 | case GL_SAMPLE_COVERAGE: |
| 772 | case GL_SCISSOR_TEST: |
| 773 | case GL_STENCIL_TEST: |
| 774 | case GL_DEPTH_TEST: |
| 775 | case GL_BLEND: |
| 776 | case GL_DITHER: |
| 777 | return true; |
| 778 | |
| 779 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 780 | case GL_RASTERIZER_DISCARD: |
| 781 | return (context->getClientMajorVersion() >= 3); |
| 782 | |
| 783 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 784 | case GL_DEBUG_OUTPUT: |
| 785 | return context->getExtensions().debug; |
| 786 | |
| 787 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 788 | return queryOnly && context->getExtensions().bindGeneratesResource; |
| 789 | |
| 790 | case GL_CLIENT_ARRAYS_ANGLE: |
| 791 | return queryOnly && context->getExtensions().clientArrays; |
| 792 | |
| 793 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 794 | return context->getExtensions().sRGBWriteControl; |
| 795 | |
| 796 | case GL_SAMPLE_MASK: |
| 797 | return context->getClientVersion() >= Version(3, 1); |
| 798 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 799 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 800 | return queryOnly && context->getExtensions().robustResourceInitialization; |
| 801 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 802 | // GLES1 emulation: GLES1-specific caps |
| 803 | case GL_ALPHA_TEST: |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 804 | case GL_VERTEX_ARRAY: |
| 805 | case GL_NORMAL_ARRAY: |
| 806 | case GL_COLOR_ARRAY: |
| 807 | case GL_TEXTURE_COORD_ARRAY: |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 808 | case GL_TEXTURE_2D: |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 809 | case GL_LIGHTING: |
| 810 | case GL_LIGHT0: |
| 811 | case GL_LIGHT1: |
| 812 | case GL_LIGHT2: |
| 813 | case GL_LIGHT3: |
| 814 | case GL_LIGHT4: |
| 815 | case GL_LIGHT5: |
| 816 | case GL_LIGHT6: |
| 817 | case GL_LIGHT7: |
| 818 | case GL_NORMALIZE: |
| 819 | case GL_RESCALE_NORMAL: |
| 820 | case GL_COLOR_MATERIAL: |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 821 | case GL_CLIP_PLANE0: |
| 822 | case GL_CLIP_PLANE1: |
| 823 | case GL_CLIP_PLANE2: |
| 824 | case GL_CLIP_PLANE3: |
| 825 | case GL_CLIP_PLANE4: |
| 826 | case GL_CLIP_PLANE5: |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 827 | case GL_FOG: |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 828 | case GL_POINT_SMOOTH: |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 829 | case GL_LINE_SMOOTH: |
| 830 | case GL_COLOR_LOGIC_OP: |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 831 | return context->getClientVersion() < Version(2, 0); |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 832 | case GL_POINT_SIZE_ARRAY_OES: |
| 833 | return context->getClientVersion() < Version(2, 0) && |
| 834 | context->getExtensions().pointSizeArray; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 835 | case GL_TEXTURE_CUBE_MAP: |
| 836 | return context->getClientVersion() < Version(2, 0) && |
| 837 | context->getExtensions().textureCubeMap; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 838 | case GL_POINT_SPRITE_OES: |
| 839 | return context->getClientVersion() < Version(2, 0) && |
| 840 | context->getExtensions().pointSprite; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 841 | default: |
| 842 | return false; |
| 843 | } |
| 844 | } |
| 845 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 846 | // Return true if a character belongs to the ASCII subset as defined in GLSL ES 1.0 spec section |
| 847 | // 3.1. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 848 | bool IsValidESSLCharacter(unsigned char c) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 849 | { |
| 850 | // Printing characters are valid except " $ ` @ \ ' DEL. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 851 | if (c >= 32 && c <= 126 && c != '"' && c != '$' && c != '`' && c != '@' && c != '\\' && |
| 852 | c != '\'') |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 853 | { |
| 854 | return true; |
| 855 | } |
| 856 | |
| 857 | // Horizontal tab, line feed, vertical tab, form feed, carriage return are also valid. |
| 858 | if (c >= 9 && c <= 13) |
| 859 | { |
| 860 | return true; |
| 861 | } |
| 862 | |
| 863 | return false; |
| 864 | } |
| 865 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 866 | bool IsValidESSLString(const char *str, size_t len) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 867 | { |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 868 | for (size_t i = 0; i < len; i++) |
| 869 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 870 | if (!IsValidESSLCharacter(str[i])) |
Geoff Lang | a71a98e | 2017-06-19 15:15:00 -0400 | [diff] [blame] | 871 | { |
| 872 | return false; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | return true; |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 877 | } |
| 878 | |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 879 | bool IsValidESSLShaderSourceString(const char *str, size_t len, bool lineContinuationAllowed) |
| 880 | { |
| 881 | enum class ParseState |
| 882 | { |
| 883 | // Have not seen an ASCII non-whitespace character yet on |
| 884 | // this line. Possible that we might see a preprocessor |
| 885 | // directive. |
| 886 | BEGINING_OF_LINE, |
| 887 | |
| 888 | // Have seen at least one ASCII non-whitespace character |
| 889 | // on this line. |
| 890 | MIDDLE_OF_LINE, |
| 891 | |
| 892 | // Handling a preprocessor directive. Passes through all |
| 893 | // characters up to the end of the line. Disables comment |
| 894 | // processing. |
| 895 | IN_PREPROCESSOR_DIRECTIVE, |
| 896 | |
| 897 | // Handling a single-line comment. The comment text is |
| 898 | // replaced with a single space. |
| 899 | IN_SINGLE_LINE_COMMENT, |
| 900 | |
| 901 | // Handling a multi-line comment. Newlines are passed |
| 902 | // through to preserve line numbers. |
| 903 | IN_MULTI_LINE_COMMENT |
| 904 | }; |
| 905 | |
| 906 | ParseState state = ParseState::BEGINING_OF_LINE; |
| 907 | size_t pos = 0; |
| 908 | |
| 909 | while (pos < len) |
| 910 | { |
| 911 | char c = str[pos]; |
| 912 | char next = pos + 1 < len ? str[pos + 1] : 0; |
| 913 | |
| 914 | // Check for newlines |
| 915 | if (c == '\n' || c == '\r') |
| 916 | { |
| 917 | if (state != ParseState::IN_MULTI_LINE_COMMENT) |
| 918 | { |
| 919 | state = ParseState::BEGINING_OF_LINE; |
| 920 | } |
| 921 | |
| 922 | pos++; |
| 923 | continue; |
| 924 | } |
| 925 | |
| 926 | switch (state) |
| 927 | { |
| 928 | case ParseState::BEGINING_OF_LINE: |
| 929 | if (c == ' ') |
| 930 | { |
| 931 | // Maintain the BEGINING_OF_LINE state until a non-space is seen |
| 932 | pos++; |
| 933 | } |
| 934 | else if (c == '#') |
| 935 | { |
| 936 | state = ParseState::IN_PREPROCESSOR_DIRECTIVE; |
| 937 | pos++; |
| 938 | } |
| 939 | else |
| 940 | { |
| 941 | // Don't advance, re-process this character with the MIDDLE_OF_LINE state |
| 942 | state = ParseState::MIDDLE_OF_LINE; |
| 943 | } |
| 944 | break; |
| 945 | |
| 946 | case ParseState::MIDDLE_OF_LINE: |
| 947 | if (c == '/' && next == '/') |
| 948 | { |
| 949 | state = ParseState::IN_SINGLE_LINE_COMMENT; |
| 950 | pos++; |
| 951 | } |
| 952 | else if (c == '/' && next == '*') |
| 953 | { |
| 954 | state = ParseState::IN_MULTI_LINE_COMMENT; |
| 955 | pos++; |
| 956 | } |
| 957 | else if (lineContinuationAllowed && c == '\\' && (next == '\n' || next == '\r')) |
| 958 | { |
| 959 | // Skip line continuation characters |
| 960 | } |
| 961 | else if (!IsValidESSLCharacter(c)) |
| 962 | { |
| 963 | return false; |
| 964 | } |
| 965 | pos++; |
| 966 | break; |
| 967 | |
| 968 | case ParseState::IN_PREPROCESSOR_DIRECTIVE: |
Bryan Bernhart (Intel Americas Inc) | 335d8bf | 2017-10-23 15:41:43 -0700 | [diff] [blame] | 969 | // Line-continuation characters may not be permitted. |
| 970 | // Otherwise, just pass it through. Do not parse comments in this state. |
| 971 | if (!lineContinuationAllowed && c == '\\') |
| 972 | { |
| 973 | return false; |
| 974 | } |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 975 | pos++; |
| 976 | break; |
| 977 | |
| 978 | case ParseState::IN_SINGLE_LINE_COMMENT: |
| 979 | // Line-continuation characters are processed before comment processing. |
| 980 | // Advance string if a new line character is immediately behind |
| 981 | // line-continuation character. |
| 982 | if (c == '\\' && (next == '\n' || next == '\r')) |
| 983 | { |
| 984 | pos++; |
| 985 | } |
| 986 | pos++; |
| 987 | break; |
| 988 | |
| 989 | case ParseState::IN_MULTI_LINE_COMMENT: |
| 990 | if (c == '*' && next == '/') |
| 991 | { |
| 992 | state = ParseState::MIDDLE_OF_LINE; |
| 993 | pos++; |
| 994 | } |
| 995 | pos++; |
| 996 | break; |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | return true; |
| 1001 | } |
| 1002 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1003 | bool ValidateWebGLNamePrefix(Context *context, const GLchar *name) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1004 | { |
| 1005 | ASSERT(context->isWebGL()); |
| 1006 | |
| 1007 | // WebGL 1.0 [Section 6.16] GLSL Constructs |
| 1008 | // Identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. |
| 1009 | if (strncmp(name, "webgl_", 6) == 0 || strncmp(name, "_webgl_", 7) == 0) |
| 1010 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1011 | context->validationError(GL_INVALID_OPERATION, kErrorWebglBindAttribLocationReservedPrefix); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | return true; |
| 1016 | } |
| 1017 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1018 | bool ValidateWebGLNameLength(Context *context, size_t length) |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1019 | { |
| 1020 | ASSERT(context->isWebGL()); |
| 1021 | |
| 1022 | if (context->isWebGL1() && length > 256) |
| 1023 | { |
| 1024 | // WebGL 1.0 [Section 6.21] Maxmimum Uniform and Attribute Location Lengths |
| 1025 | // WebGL imposes a limit of 256 characters on the lengths of uniform and attribute |
| 1026 | // locations. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1027 | context->validationError(GL_INVALID_VALUE, kErrorWebglNameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1028 | |
| 1029 | return false; |
| 1030 | } |
| 1031 | else if (length > 1024) |
| 1032 | { |
| 1033 | // WebGL 2.0 [Section 4.3.2] WebGL 2.0 imposes a limit of 1024 characters on the lengths of |
| 1034 | // uniform and attribute locations. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1035 | context->validationError(GL_INVALID_VALUE, kErrorWebgl2NameLengthLimitExceeded); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 1036 | return false; |
| 1037 | } |
| 1038 | |
| 1039 | return true; |
| 1040 | } |
| 1041 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1042 | bool ValidateMatrixMode(Context *context, GLenum matrixMode) |
| 1043 | { |
| 1044 | if (!context->getExtensions().pathRendering) |
| 1045 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1046 | context->validationError(GL_INVALID_OPERATION, |
| 1047 | "GL_CHROMIUM_path_rendering is not available."); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1048 | return false; |
| 1049 | } |
| 1050 | |
| 1051 | if (matrixMode != GL_PATH_MODELVIEW_CHROMIUM && matrixMode != GL_PATH_PROJECTION_CHROMIUM) |
| 1052 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1053 | context->validationError(GL_INVALID_ENUM, kErrorInvalidMatrixMode); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 1054 | return false; |
| 1055 | } |
| 1056 | return true; |
| 1057 | } |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 1058 | |
| 1059 | bool ValidBlendFunc(const Context *context, GLenum val) |
| 1060 | { |
| 1061 | const gl::Extensions &ext = context->getExtensions(); |
| 1062 | |
| 1063 | // these are always valid for src and dst. |
| 1064 | switch (val) |
| 1065 | { |
| 1066 | case GL_ZERO: |
| 1067 | case GL_ONE: |
| 1068 | case GL_SRC_COLOR: |
| 1069 | case GL_ONE_MINUS_SRC_COLOR: |
| 1070 | case GL_DST_COLOR: |
| 1071 | case GL_ONE_MINUS_DST_COLOR: |
| 1072 | case GL_SRC_ALPHA: |
| 1073 | case GL_ONE_MINUS_SRC_ALPHA: |
| 1074 | case GL_DST_ALPHA: |
| 1075 | case GL_ONE_MINUS_DST_ALPHA: |
| 1076 | case GL_CONSTANT_COLOR: |
| 1077 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 1078 | case GL_CONSTANT_ALPHA: |
| 1079 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 1080 | return true; |
| 1081 | |
| 1082 | // EXT_blend_func_extended. |
| 1083 | case GL_SRC1_COLOR_EXT: |
| 1084 | case GL_SRC1_ALPHA_EXT: |
| 1085 | case GL_ONE_MINUS_SRC1_COLOR_EXT: |
| 1086 | case GL_ONE_MINUS_SRC1_ALPHA_EXT: |
| 1087 | case GL_SRC_ALPHA_SATURATE_EXT: |
| 1088 | return ext.blendFuncExtended; |
| 1089 | |
| 1090 | default: |
| 1091 | return false; |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | bool ValidSrcBlendFunc(const Context *context, GLenum val) |
| 1096 | { |
| 1097 | if (ValidBlendFunc(context, val)) |
| 1098 | return true; |
| 1099 | |
| 1100 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1101 | return true; |
| 1102 | |
| 1103 | return false; |
| 1104 | } |
| 1105 | |
| 1106 | bool ValidDstBlendFunc(const Context *context, GLenum val) |
| 1107 | { |
| 1108 | if (ValidBlendFunc(context, val)) |
| 1109 | return true; |
| 1110 | |
| 1111 | if (val == GL_SRC_ALPHA_SATURATE) |
| 1112 | { |
| 1113 | if (context->getClientMajorVersion() >= 3) |
| 1114 | return true; |
| 1115 | } |
| 1116 | |
| 1117 | return false; |
| 1118 | } |
| 1119 | |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1120 | void RecordBindTextureTypeError(Context *context, TextureType target) |
| 1121 | { |
| 1122 | ASSERT(!context->getStateCache().isValidBindTextureType(target)); |
| 1123 | |
| 1124 | switch (target) |
| 1125 | { |
| 1126 | case TextureType::Rectangle: |
| 1127 | ASSERT(!context->getExtensions().textureRectangle); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1128 | context->validationError(GL_INVALID_ENUM, |
| 1129 | "Context does not support GL_ANGLE_texture_rectangle"); |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1130 | break; |
| 1131 | |
| 1132 | case TextureType::_3D: |
| 1133 | case TextureType::_2DArray: |
| 1134 | ASSERT(context->getClientMajorVersion() < 3); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1135 | context->validationError(GL_INVALID_ENUM, kErrorES3Required); |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 1136 | break; |
| 1137 | |
| 1138 | case TextureType::_2DMultisample: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 1139 | ASSERT(context->getClientVersion() < Version(3, 1) && |
| 1140 | !context->getExtensions().textureMultisample); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1141 | context->validationError(GL_INVALID_ENUM, |
| 1142 | kErrorMultisampleTextureExtensionOrES31Required); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1147 | context->validationError(GL_INVALID_ENUM, kErrorMultisampleArrayExtensionRequired); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1157 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1180 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1193 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1200 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxTextureSize); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1215 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormatCombination); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1227 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxTextureSize); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1237 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxTextureSize); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1251 | context->validationError(GL_INVALID_VALUE, kErrorCubemapFacesEqualDimensions); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1258 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxTextureSize); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1259 | return false; |
| 1260 | } |
| 1261 | break; |
| 1262 | |
| 1263 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1264 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1271 | context->validationError(GL_INVALID_OPERATION, kErrorBufferNotBound); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1289 | context->validationError(GL_INVALID_OPERATION, kErrorTypeMismatch); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1297 | context->validationError(GL_INVALID_VALUE, kErrorOffsetOverflow); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1304 | context->validationError(GL_INVALID_VALUE, kErrorPixelDataNull); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1312 | context->validationError(GL_INVALID_OPERATION, kErrorTextureIsImmutable); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1320 | context->validationError(GL_INVALID_VALUE, kErrorInvalidBorder); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1334 | context->validationError(GL_INVALID_ENUM, kErrorInvalidInternalFormat); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1341 | context->validationError(GL_INVALID_ENUM, kErrorInvalidInternalFormat); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1353 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidInternalFormat); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1368 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1398 | context->validationError(GL_INVALID_ENUM, kErrorInvalidType); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1417 | context->validationError(GL_INVALID_OPERATION, |
| 1418 | kErrorMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1419 | return false; |
| 1420 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1421 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1422 | case GL_RED: |
| 1423 | case GL_RG: |
| 1424 | if (!context->getExtensions().textureRG) |
| 1425 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1426 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1427 | return false; |
| 1428 | } |
| 1429 | switch (type) |
| 1430 | { |
| 1431 | case GL_UNSIGNED_BYTE: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1432 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1433 | case GL_FLOAT: |
| 1434 | case GL_HALF_FLOAT_OES: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1435 | if (!context->getExtensions().textureFloat) |
| 1436 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1437 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1438 | return false; |
| 1439 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1440 | break; |
| 1441 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1442 | context->validationError(GL_INVALID_OPERATION, |
| 1443 | kErrorMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1444 | return false; |
| 1445 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1446 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1447 | case GL_RGB: |
| 1448 | switch (type) |
| 1449 | { |
| 1450 | case GL_UNSIGNED_BYTE: |
| 1451 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1452 | case GL_FLOAT: |
| 1453 | case GL_HALF_FLOAT_OES: |
| 1454 | break; |
| 1455 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1456 | context->validationError(GL_INVALID_OPERATION, |
| 1457 | kErrorMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1458 | return false; |
| 1459 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1460 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1461 | case GL_RGBA: |
| 1462 | switch (type) |
| 1463 | { |
| 1464 | case GL_UNSIGNED_BYTE: |
| 1465 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1466 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1467 | case GL_FLOAT: |
| 1468 | case GL_HALF_FLOAT_OES: |
| 1469 | break; |
| 1470 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1471 | context->validationError(GL_INVALID_OPERATION, |
| 1472 | kErrorMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1473 | return false; |
| 1474 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1475 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1476 | case GL_BGRA_EXT: |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1477 | if (!context->getExtensions().textureFormatBGRA8888) |
| 1478 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1479 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Bryan Bernhart (Intel Americas Inc) | 2a35741 | 2017-09-05 10:42:47 -0700 | [diff] [blame] | 1480 | return false; |
| 1481 | } |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1482 | switch (type) |
| 1483 | { |
| 1484 | case GL_UNSIGNED_BYTE: |
| 1485 | break; |
| 1486 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1487 | context->validationError(GL_INVALID_OPERATION, |
| 1488 | kErrorMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1489 | return false; |
| 1490 | } |
| 1491 | break; |
| 1492 | case GL_SRGB_EXT: |
| 1493 | case GL_SRGB_ALPHA_EXT: |
| 1494 | if (!context->getExtensions().sRGB) |
| 1495 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1496 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1497 | return false; |
| 1498 | } |
| 1499 | switch (type) |
| 1500 | { |
| 1501 | case GL_UNSIGNED_BYTE: |
| 1502 | break; |
| 1503 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1504 | context->validationError(GL_INVALID_OPERATION, |
| 1505 | kErrorMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1506 | return false; |
| 1507 | } |
| 1508 | break; |
| 1509 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are |
| 1510 | // handled below |
| 1511 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1512 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1513 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1514 | break; |
| 1515 | case GL_DEPTH_COMPONENT: |
| 1516 | switch (type) |
| 1517 | { |
| 1518 | case GL_UNSIGNED_SHORT: |
| 1519 | case GL_UNSIGNED_INT: |
| 1520 | break; |
| 1521 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1522 | context->validationError(GL_INVALID_OPERATION, |
| 1523 | kErrorMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1524 | return false; |
| 1525 | } |
| 1526 | break; |
| 1527 | case GL_DEPTH_STENCIL_OES: |
| 1528 | switch (type) |
| 1529 | { |
| 1530 | case GL_UNSIGNED_INT_24_8_OES: |
| 1531 | break; |
| 1532 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1533 | context->validationError(GL_INVALID_OPERATION, |
| 1534 | kErrorMismatchedTypeAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1535 | return false; |
| 1536 | } |
| 1537 | break; |
| 1538 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1539 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1540 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | switch (format) |
| 1544 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1545 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1546 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1547 | if (context->getExtensions().textureCompressionDXT1) |
| 1548 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1549 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1550 | return false; |
| 1551 | } |
| 1552 | else |
| 1553 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1554 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1555 | return false; |
| 1556 | } |
| 1557 | break; |
| 1558 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1559 | if (context->getExtensions().textureCompressionDXT3) |
| 1560 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1561 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1562 | return false; |
| 1563 | } |
| 1564 | else |
| 1565 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1566 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1567 | return false; |
| 1568 | } |
| 1569 | break; |
| 1570 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1571 | if (context->getExtensions().textureCompressionDXT5) |
| 1572 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1573 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1574 | return false; |
| 1575 | } |
| 1576 | else |
| 1577 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1578 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1579 | return false; |
| 1580 | } |
| 1581 | break; |
| 1582 | case GL_ETC1_RGB8_OES: |
| 1583 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 1584 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1585 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1586 | return false; |
| 1587 | } |
| 1588 | else |
| 1589 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1590 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1591 | return false; |
| 1592 | } |
| 1593 | break; |
| 1594 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1595 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1596 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1597 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1598 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1599 | if (context->getExtensions().lossyETCDecode) |
| 1600 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1601 | context->validationError(GL_INVALID_OPERATION, |
| 1602 | "ETC lossy decode formats can't work with this type."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1603 | return false; |
| 1604 | } |
| 1605 | else |
| 1606 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1607 | context->validationError(GL_INVALID_ENUM, |
| 1608 | "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1609 | return false; |
| 1610 | } |
| 1611 | break; |
| 1612 | case GL_DEPTH_COMPONENT: |
| 1613 | case GL_DEPTH_STENCIL_OES: |
| 1614 | if (!context->getExtensions().depthTextures) |
| 1615 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1616 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1617 | return false; |
| 1618 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1619 | if (target != TextureTarget::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1620 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1621 | context->validationError(GL_INVALID_OPERATION, kErrorMismatchedTargetAndFormat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1622 | return false; |
| 1623 | } |
| 1624 | // OES_depth_texture supports loading depth data and multiple levels, |
| 1625 | // but ANGLE_depth_texture does not |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1626 | if (pixels != nullptr) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1627 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1628 | context->validationError(GL_INVALID_OPERATION, kErrorPixelDataNotNull); |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1629 | return false; |
| 1630 | } |
| 1631 | if (level != 0) |
| 1632 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1633 | context->validationError(GL_INVALID_OPERATION, kErrorLevelNotZero); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1634 | return false; |
| 1635 | } |
| 1636 | break; |
| 1637 | default: |
| 1638 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1639 | } |
| 1640 | |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1641 | if (!isSubImage) |
| 1642 | { |
| 1643 | switch (internalformat) |
| 1644 | { |
| 1645 | case GL_RGBA32F: |
| 1646 | if (!context->getExtensions().colorBufferFloatRGBA) |
| 1647 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1648 | context->validationError(GL_INVALID_ENUM, |
| 1649 | "Sized GL_RGBA32F internal format requires " |
| 1650 | "GL_CHROMIUM_color_buffer_float_rgba"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1651 | return false; |
| 1652 | } |
| 1653 | if (type != GL_FLOAT) |
| 1654 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1655 | context->validationError(GL_INVALID_OPERATION, |
| 1656 | kErrorMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1657 | return false; |
| 1658 | } |
| 1659 | if (format != GL_RGBA) |
| 1660 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1661 | context->validationError(GL_INVALID_OPERATION, |
| 1662 | kErrorMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1663 | return false; |
| 1664 | } |
| 1665 | break; |
| 1666 | |
| 1667 | case GL_RGB32F: |
| 1668 | if (!context->getExtensions().colorBufferFloatRGB) |
| 1669 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1670 | context->validationError(GL_INVALID_ENUM, |
| 1671 | "Sized GL_RGB32F internal format requires " |
| 1672 | "GL_CHROMIUM_color_buffer_float_rgb"); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1673 | return false; |
| 1674 | } |
| 1675 | if (type != GL_FLOAT) |
| 1676 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1677 | context->validationError(GL_INVALID_OPERATION, |
| 1678 | kErrorMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1679 | return false; |
| 1680 | } |
| 1681 | if (format != GL_RGB) |
| 1682 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1683 | context->validationError(GL_INVALID_OPERATION, |
| 1684 | kErrorMismatchedTypeAndFormat); |
Geoff Lang | 6e898aa | 2017-06-02 11:17:26 -0400 | [diff] [blame] | 1685 | return false; |
| 1686 | } |
| 1687 | break; |
| 1688 | |
| 1689 | default: |
| 1690 | break; |
| 1691 | } |
| 1692 | } |
| 1693 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1694 | if (type == GL_FLOAT) |
| 1695 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1696 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1697 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1698 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1699 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1700 | } |
| 1701 | } |
| 1702 | else if (type == GL_HALF_FLOAT_OES) |
| 1703 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1704 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1705 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1706 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1707 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 1712 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1713 | if (!ValidImageDataSize(context, texType, width, height, 1, sizeCheckFormat, type, pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1714 | imageSize)) |
| 1715 | { |
| 1716 | return false; |
| 1717 | } |
| 1718 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1719 | return true; |
| 1720 | } |
| 1721 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1722 | bool ValidateES2TexStorageParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1723 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1724 | GLsizei levels, |
| 1725 | GLenum internalformat, |
| 1726 | GLsizei width, |
| 1727 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1728 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1729 | if (target != TextureType::_2D && target != TextureType::CubeMap && |
| 1730 | target != TextureType::Rectangle) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1731 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1732 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
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 (width < 1 || height < 1 || levels < 1) |
| 1737 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1738 | context->validationError(GL_INVALID_VALUE, kErrorTextureSizeTooSmall); |
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 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1742 | if (target == TextureType::CubeMap && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1743 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1744 | context->validationError(GL_INVALID_VALUE, kErrorCubemapFacesEqualDimensions); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1745 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 1749 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1750 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidMipLevels); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1751 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1752 | } |
| 1753 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1754 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1755 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1756 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1757 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1758 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1759 | } |
| 1760 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1761 | const gl::Caps &caps = context->getCaps(); |
| 1762 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1763 | switch (target) |
| 1764 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1765 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1766 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1767 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 1768 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1769 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1770 | return false; |
| 1771 | } |
| 1772 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1773 | case TextureType::Rectangle: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1774 | if (levels != 1) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1775 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1776 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
| 1777 | return false; |
| 1778 | } |
| 1779 | |
| 1780 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1781 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 1782 | { |
| 1783 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxTextureSize); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1784 | return false; |
| 1785 | } |
| 1786 | if (formatInfo.compressed) |
| 1787 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1788 | context->validationError(GL_INVALID_ENUM, kErrorRectangleTextureCompressed); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1789 | return false; |
| 1790 | } |
| 1791 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1792 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1793 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 1794 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
| 1795 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1796 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxTextureSize); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1797 | return false; |
| 1798 | } |
| 1799 | break; |
| 1800 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1801 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1802 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1803 | } |
| 1804 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1805 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1806 | { |
| 1807 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 1808 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1809 | context->validationError(GL_INVALID_OPERATION, kErrorDimensionsMustBePow2); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1810 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | switch (internalformat) |
| 1815 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1816 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1817 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1818 | if (!context->getExtensions().textureCompressionDXT1) |
| 1819 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1820 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1821 | return false; |
| 1822 | } |
| 1823 | break; |
| 1824 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1825 | if (!context->getExtensions().textureCompressionDXT3) |
| 1826 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1827 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1828 | return false; |
| 1829 | } |
| 1830 | break; |
| 1831 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 1832 | if (!context->getExtensions().textureCompressionDXT5) |
| 1833 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1834 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1835 | return false; |
| 1836 | } |
| 1837 | break; |
| 1838 | case GL_ETC1_RGB8_OES: |
| 1839 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 1840 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1841 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1842 | return false; |
| 1843 | } |
| 1844 | break; |
| 1845 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Minmin Gong | 390208b | 2017-02-28 18:03:06 -0800 | [diff] [blame] | 1846 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1847 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 1848 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 1849 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1850 | if (!context->getExtensions().lossyETCDecode) |
| 1851 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1852 | context->validationError(GL_INVALID_ENUM, |
| 1853 | "ANGLE_lossy_etc_decode extension is not supported."); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1854 | return false; |
| 1855 | } |
| 1856 | break; |
| 1857 | case GL_RGBA32F_EXT: |
| 1858 | case GL_RGB32F_EXT: |
| 1859 | case GL_ALPHA32F_EXT: |
| 1860 | case GL_LUMINANCE32F_EXT: |
| 1861 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 1862 | if (!context->getExtensions().textureFloat) |
| 1863 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1864 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1865 | return false; |
| 1866 | } |
| 1867 | break; |
| 1868 | case GL_RGBA16F_EXT: |
| 1869 | case GL_RGB16F_EXT: |
| 1870 | case GL_ALPHA16F_EXT: |
| 1871 | case GL_LUMINANCE16F_EXT: |
| 1872 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 1873 | if (!context->getExtensions().textureHalfFloat) |
| 1874 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1875 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1876 | return false; |
| 1877 | } |
| 1878 | break; |
| 1879 | case GL_R8_EXT: |
| 1880 | case GL_RG8_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1881 | if (!context->getExtensions().textureRG) |
| 1882 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1883 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1884 | return false; |
| 1885 | } |
| 1886 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1887 | case GL_R16F_EXT: |
| 1888 | case GL_RG16F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1889 | if (!context->getExtensions().textureRG || !context->getExtensions().textureHalfFloat) |
| 1890 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1891 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1892 | return false; |
| 1893 | } |
| 1894 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1895 | case GL_R32F_EXT: |
| 1896 | case GL_RG32F_EXT: |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1897 | if (!context->getExtensions().textureRG || !context->getExtensions().textureFloat) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1898 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1899 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1900 | return false; |
| 1901 | } |
| 1902 | break; |
| 1903 | case GL_DEPTH_COMPONENT16: |
| 1904 | case GL_DEPTH_COMPONENT32_OES: |
| 1905 | case GL_DEPTH24_STENCIL8_OES: |
| 1906 | if (!context->getExtensions().depthTextures) |
| 1907 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1908 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1909 | return false; |
| 1910 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1911 | if (target != TextureType::_2D) |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1912 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1913 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1914 | return false; |
| 1915 | } |
| 1916 | // ANGLE_depth_texture only supports 1-level textures |
| 1917 | if (levels != 1) |
| 1918 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1919 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidMipLevels); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1920 | return false; |
| 1921 | } |
| 1922 | break; |
| 1923 | default: |
| 1924 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1925 | } |
| 1926 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1927 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1928 | if (!texture || texture->id() == 0) |
| 1929 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1930 | context->validationError(GL_INVALID_OPERATION, kErrorMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1931 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1932 | } |
| 1933 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1934 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1935 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1936 | context->validationError(GL_INVALID_OPERATION, kErrorTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1937 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | return true; |
| 1941 | } |
| 1942 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1943 | bool ValidateDiscardFramebufferEXT(Context *context, |
| 1944 | GLenum target, |
| 1945 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1946 | const GLenum *attachments) |
| 1947 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1948 | if (!context->getExtensions().discardFramebuffer) |
| 1949 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1950 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1951 | return false; |
| 1952 | } |
| 1953 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1954 | bool defaultFramebuffer = false; |
| 1955 | |
| 1956 | switch (target) |
| 1957 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1958 | case GL_FRAMEBUFFER: |
| 1959 | defaultFramebuffer = |
| 1960 | (context->getGLState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
| 1961 | break; |
| 1962 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1963 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1964 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1967 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1968 | defaultFramebuffer); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1971 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 1972 | { |
| 1973 | if (!context->getExtensions().vertexArrayObject) |
| 1974 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1975 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1976 | return false; |
| 1977 | } |
| 1978 | |
| 1979 | return ValidateBindVertexArrayBase(context, array); |
| 1980 | } |
| 1981 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1982 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n, const GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1983 | { |
| 1984 | if (!context->getExtensions().vertexArrayObject) |
| 1985 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1986 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1987 | return false; |
| 1988 | } |
| 1989 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1990 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1993 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n, GLuint *arrays) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1994 | { |
| 1995 | if (!context->getExtensions().vertexArrayObject) |
| 1996 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 1997 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1998 | return false; |
| 1999 | } |
| 2000 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2001 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 2004 | bool ValidateIsVertexArrayOES(Context *context, GLuint array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2005 | { |
| 2006 | if (!context->getExtensions().vertexArrayObject) |
| 2007 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2008 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
| 2011 | |
| 2012 | return true; |
| 2013 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2014 | |
| 2015 | bool ValidateProgramBinaryOES(Context *context, |
| 2016 | GLuint program, |
| 2017 | GLenum binaryFormat, |
| 2018 | const void *binary, |
| 2019 | GLint length) |
| 2020 | { |
| 2021 | if (!context->getExtensions().getProgramBinary) |
| 2022 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2023 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2024 | return false; |
| 2025 | } |
| 2026 | |
| 2027 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 2028 | } |
| 2029 | |
| 2030 | bool ValidateGetProgramBinaryOES(Context *context, |
| 2031 | GLuint program, |
| 2032 | GLsizei bufSize, |
| 2033 | GLsizei *length, |
| 2034 | GLenum *binaryFormat, |
| 2035 | void *binary) |
| 2036 | { |
| 2037 | if (!context->getExtensions().getProgramBinary) |
| 2038 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2039 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2040 | return false; |
| 2041 | } |
| 2042 | |
| 2043 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 2044 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2045 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2046 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 2047 | { |
| 2048 | switch (source) |
| 2049 | { |
| 2050 | case GL_DEBUG_SOURCE_API: |
| 2051 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 2052 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 2053 | case GL_DEBUG_SOURCE_OTHER: |
| 2054 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 2055 | return !mustBeThirdPartyOrApplication; |
| 2056 | |
| 2057 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 2058 | case GL_DEBUG_SOURCE_APPLICATION: |
| 2059 | return true; |
| 2060 | |
| 2061 | default: |
| 2062 | return false; |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | static bool ValidDebugType(GLenum type) |
| 2067 | { |
| 2068 | switch (type) |
| 2069 | { |
| 2070 | case GL_DEBUG_TYPE_ERROR: |
| 2071 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 2072 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 2073 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 2074 | case GL_DEBUG_TYPE_PORTABILITY: |
| 2075 | case GL_DEBUG_TYPE_OTHER: |
| 2076 | case GL_DEBUG_TYPE_MARKER: |
| 2077 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 2078 | case GL_DEBUG_TYPE_POP_GROUP: |
| 2079 | return true; |
| 2080 | |
| 2081 | default: |
| 2082 | return false; |
| 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | static bool ValidDebugSeverity(GLenum severity) |
| 2087 | { |
| 2088 | switch (severity) |
| 2089 | { |
| 2090 | case GL_DEBUG_SEVERITY_HIGH: |
| 2091 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 2092 | case GL_DEBUG_SEVERITY_LOW: |
| 2093 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 2094 | return true; |
| 2095 | |
| 2096 | default: |
| 2097 | return false; |
| 2098 | } |
| 2099 | } |
| 2100 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2101 | bool ValidateDebugMessageControlKHR(Context *context, |
| 2102 | GLenum source, |
| 2103 | GLenum type, |
| 2104 | GLenum severity, |
| 2105 | GLsizei count, |
| 2106 | const GLuint *ids, |
| 2107 | GLboolean enabled) |
| 2108 | { |
| 2109 | if (!context->getExtensions().debug) |
| 2110 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2111 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2112 | return false; |
| 2113 | } |
| 2114 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2115 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 2116 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2117 | context->validationError(GL_INVALID_ENUM, kErrorInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2118 | return false; |
| 2119 | } |
| 2120 | |
| 2121 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 2122 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2123 | context->validationError(GL_INVALID_ENUM, kErrorInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2124 | return false; |
| 2125 | } |
| 2126 | |
| 2127 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 2128 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2129 | context->validationError(GL_INVALID_ENUM, kErrorInvalidDebugSeverity); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2130 | return false; |
| 2131 | } |
| 2132 | |
| 2133 | if (count > 0) |
| 2134 | { |
| 2135 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 2136 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2137 | context->validationError( |
| 2138 | GL_INVALID_OPERATION, |
| 2139 | "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] | 2140 | return false; |
| 2141 | } |
| 2142 | |
| 2143 | if (severity != GL_DONT_CARE) |
| 2144 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2145 | context->validationError( |
| 2146 | GL_INVALID_OPERATION, |
| 2147 | "If count is greater than zero, severity must be GL_DONT_CARE."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2148 | return false; |
| 2149 | } |
| 2150 | } |
| 2151 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2152 | return true; |
| 2153 | } |
| 2154 | |
| 2155 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 2156 | GLenum source, |
| 2157 | GLenum type, |
| 2158 | GLuint id, |
| 2159 | GLenum severity, |
| 2160 | GLsizei length, |
| 2161 | const GLchar *buf) |
| 2162 | { |
| 2163 | if (!context->getExtensions().debug) |
| 2164 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2165 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2166 | return false; |
| 2167 | } |
| 2168 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2169 | if (!context->getGLState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2170 | { |
| 2171 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 2172 | // not generate an error. |
| 2173 | return false; |
| 2174 | } |
| 2175 | |
| 2176 | if (!ValidDebugSeverity(severity)) |
| 2177 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2178 | context->validationError(GL_INVALID_ENUM, kErrorInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2179 | return false; |
| 2180 | } |
| 2181 | |
| 2182 | if (!ValidDebugType(type)) |
| 2183 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2184 | context->validationError(GL_INVALID_ENUM, kErrorInvalidDebugType); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2185 | return false; |
| 2186 | } |
| 2187 | |
| 2188 | if (!ValidDebugSource(source, true)) |
| 2189 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2190 | context->validationError(GL_INVALID_ENUM, kErrorInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2191 | return false; |
| 2192 | } |
| 2193 | |
| 2194 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 2195 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2196 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2197 | context->validationError(GL_INVALID_VALUE, |
| 2198 | "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2199 | return false; |
| 2200 | } |
| 2201 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2202 | return true; |
| 2203 | } |
| 2204 | |
| 2205 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 2206 | GLDEBUGPROCKHR callback, |
| 2207 | const void *userParam) |
| 2208 | { |
| 2209 | if (!context->getExtensions().debug) |
| 2210 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2211 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2212 | return false; |
| 2213 | } |
| 2214 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2215 | return true; |
| 2216 | } |
| 2217 | |
| 2218 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 2219 | GLuint count, |
| 2220 | GLsizei bufSize, |
| 2221 | GLenum *sources, |
| 2222 | GLenum *types, |
| 2223 | GLuint *ids, |
| 2224 | GLenum *severities, |
| 2225 | GLsizei *lengths, |
| 2226 | GLchar *messageLog) |
| 2227 | { |
| 2228 | if (!context->getExtensions().debug) |
| 2229 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2230 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2231 | return false; |
| 2232 | } |
| 2233 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2234 | if (bufSize < 0 && messageLog != nullptr) |
| 2235 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2236 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2237 | return false; |
| 2238 | } |
| 2239 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2240 | return true; |
| 2241 | } |
| 2242 | |
| 2243 | bool ValidatePushDebugGroupKHR(Context *context, |
| 2244 | GLenum source, |
| 2245 | GLuint id, |
| 2246 | GLsizei length, |
| 2247 | const GLchar *message) |
| 2248 | { |
| 2249 | if (!context->getExtensions().debug) |
| 2250 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2251 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2252 | return false; |
| 2253 | } |
| 2254 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2255 | if (!ValidDebugSource(source, true)) |
| 2256 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2257 | context->validationError(GL_INVALID_ENUM, kErrorInvalidDebugSource); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2258 | return false; |
| 2259 | } |
| 2260 | |
| 2261 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 2262 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 2263 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2264 | context->validationError(GL_INVALID_VALUE, |
| 2265 | "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2266 | return false; |
| 2267 | } |
| 2268 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2269 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2270 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 2271 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2272 | context->validationError( |
| 2273 | GL_STACK_OVERFLOW, |
| 2274 | "Cannot push more than GL_MAX_DEBUG_GROUP_STACK_DEPTH debug groups."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2275 | return false; |
| 2276 | } |
| 2277 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2278 | return true; |
| 2279 | } |
| 2280 | |
| 2281 | bool ValidatePopDebugGroupKHR(Context *context) |
| 2282 | { |
| 2283 | if (!context->getExtensions().debug) |
| 2284 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2285 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2286 | return false; |
| 2287 | } |
| 2288 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2289 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2290 | if (currentStackSize <= 1) |
| 2291 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2292 | context->validationError(GL_STACK_UNDERFLOW, "Cannot pop the default debug group."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2293 | return false; |
| 2294 | } |
| 2295 | |
| 2296 | return true; |
| 2297 | } |
| 2298 | |
| 2299 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 2300 | { |
| 2301 | switch (identifier) |
| 2302 | { |
| 2303 | case GL_BUFFER: |
| 2304 | if (context->getBuffer(name) == nullptr) |
| 2305 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2306 | context->validationError(GL_INVALID_VALUE, "name is not a valid buffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2307 | return false; |
| 2308 | } |
| 2309 | return true; |
| 2310 | |
| 2311 | case GL_SHADER: |
| 2312 | if (context->getShader(name) == nullptr) |
| 2313 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2314 | context->validationError(GL_INVALID_VALUE, "name is not a valid shader."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2315 | return false; |
| 2316 | } |
| 2317 | return true; |
| 2318 | |
| 2319 | case GL_PROGRAM: |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 2320 | if (context->getProgramNoResolveLink(name) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2321 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2322 | context->validationError(GL_INVALID_VALUE, "name is not a valid program."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2323 | return false; |
| 2324 | } |
| 2325 | return true; |
| 2326 | |
| 2327 | case GL_VERTEX_ARRAY: |
| 2328 | if (context->getVertexArray(name) == nullptr) |
| 2329 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2330 | context->validationError(GL_INVALID_VALUE, "name is not a valid vertex array."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2331 | return false; |
| 2332 | } |
| 2333 | return true; |
| 2334 | |
| 2335 | case GL_QUERY: |
| 2336 | if (context->getQuery(name) == nullptr) |
| 2337 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2338 | context->validationError(GL_INVALID_VALUE, "name is not a valid query."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2339 | return false; |
| 2340 | } |
| 2341 | return true; |
| 2342 | |
| 2343 | case GL_TRANSFORM_FEEDBACK: |
| 2344 | if (context->getTransformFeedback(name) == nullptr) |
| 2345 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2346 | context->validationError(GL_INVALID_VALUE, |
| 2347 | "name is not a valid transform feedback."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2348 | return false; |
| 2349 | } |
| 2350 | return true; |
| 2351 | |
| 2352 | case GL_SAMPLER: |
| 2353 | if (context->getSampler(name) == nullptr) |
| 2354 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2355 | context->validationError(GL_INVALID_VALUE, "name is not a valid sampler."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2356 | return false; |
| 2357 | } |
| 2358 | return true; |
| 2359 | |
| 2360 | case GL_TEXTURE: |
| 2361 | if (context->getTexture(name) == nullptr) |
| 2362 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2363 | context->validationError(GL_INVALID_VALUE, "name is not a valid texture."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2364 | return false; |
| 2365 | } |
| 2366 | return true; |
| 2367 | |
| 2368 | case GL_RENDERBUFFER: |
| 2369 | if (context->getRenderbuffer(name) == nullptr) |
| 2370 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2371 | context->validationError(GL_INVALID_VALUE, "name is not a valid renderbuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2372 | return false; |
| 2373 | } |
| 2374 | return true; |
| 2375 | |
| 2376 | case GL_FRAMEBUFFER: |
| 2377 | if (context->getFramebuffer(name) == nullptr) |
| 2378 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2379 | context->validationError(GL_INVALID_VALUE, "name is not a valid framebuffer."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2380 | return false; |
| 2381 | } |
| 2382 | return true; |
| 2383 | |
| 2384 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2385 | context->validationError(GL_INVALID_ENUM, "Invalid identifier."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2386 | return false; |
| 2387 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2388 | } |
| 2389 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2390 | static bool ValidateLabelLength(Context *context, GLsizei length, const GLchar *label) |
| 2391 | { |
| 2392 | size_t labelLength = 0; |
| 2393 | |
| 2394 | if (length < 0) |
| 2395 | { |
| 2396 | if (label != nullptr) |
| 2397 | { |
| 2398 | labelLength = strlen(label); |
| 2399 | } |
| 2400 | } |
| 2401 | else |
| 2402 | { |
| 2403 | labelLength = static_cast<size_t>(length); |
| 2404 | } |
| 2405 | |
| 2406 | if (labelLength > context->getExtensions().maxLabelLength) |
| 2407 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2408 | context->validationError(GL_INVALID_VALUE, |
| 2409 | "Label length is larger than GL_MAX_LABEL_LENGTH."); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2410 | return false; |
| 2411 | } |
| 2412 | |
| 2413 | return true; |
| 2414 | } |
| 2415 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2416 | bool ValidateObjectLabelKHR(Context *context, |
| 2417 | GLenum identifier, |
| 2418 | GLuint name, |
| 2419 | GLsizei length, |
| 2420 | const GLchar *label) |
| 2421 | { |
| 2422 | if (!context->getExtensions().debug) |
| 2423 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2424 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2425 | return false; |
| 2426 | } |
| 2427 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2428 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2429 | { |
| 2430 | return false; |
| 2431 | } |
| 2432 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2433 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2434 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2435 | return false; |
| 2436 | } |
| 2437 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2438 | return true; |
| 2439 | } |
| 2440 | |
| 2441 | bool ValidateGetObjectLabelKHR(Context *context, |
| 2442 | GLenum identifier, |
| 2443 | GLuint name, |
| 2444 | GLsizei bufSize, |
| 2445 | GLsizei *length, |
| 2446 | GLchar *label) |
| 2447 | { |
| 2448 | if (!context->getExtensions().debug) |
| 2449 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2450 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2451 | return false; |
| 2452 | } |
| 2453 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2454 | if (bufSize < 0) |
| 2455 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2456 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2457 | return false; |
| 2458 | } |
| 2459 | |
| 2460 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 2461 | { |
| 2462 | return false; |
| 2463 | } |
| 2464 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2465 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 2469 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 2470 | if (context->getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2471 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2472 | context->validationError(GL_INVALID_VALUE, "name is not a valid sync."); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2473 | return false; |
| 2474 | } |
| 2475 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2476 | return true; |
| 2477 | } |
| 2478 | |
| 2479 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 2480 | const void *ptr, |
| 2481 | GLsizei length, |
| 2482 | const GLchar *label) |
| 2483 | { |
| 2484 | if (!context->getExtensions().debug) |
| 2485 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2486 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2487 | return false; |
| 2488 | } |
| 2489 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2490 | if (!ValidateObjectPtrName(context, ptr)) |
| 2491 | { |
| 2492 | return false; |
| 2493 | } |
| 2494 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2495 | if (!ValidateLabelLength(context, length, label)) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2496 | { |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2497 | return false; |
| 2498 | } |
| 2499 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2500 | return true; |
| 2501 | } |
| 2502 | |
| 2503 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 2504 | const void *ptr, |
| 2505 | GLsizei bufSize, |
| 2506 | GLsizei *length, |
| 2507 | GLchar *label) |
| 2508 | { |
| 2509 | if (!context->getExtensions().debug) |
| 2510 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2511 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2512 | return false; |
| 2513 | } |
| 2514 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2515 | if (bufSize < 0) |
| 2516 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2517 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2518 | return false; |
| 2519 | } |
| 2520 | |
| 2521 | if (!ValidateObjectPtrName(context, ptr)) |
| 2522 | { |
| 2523 | return false; |
| 2524 | } |
| 2525 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 2526 | return true; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 2530 | { |
| 2531 | if (!context->getExtensions().debug) |
| 2532 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2533 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2534 | return false; |
| 2535 | } |
| 2536 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2537 | // TODO: represent this in Context::getQueryParameterInfo. |
| 2538 | switch (pname) |
| 2539 | { |
| 2540 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2541 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2542 | break; |
| 2543 | |
| 2544 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2545 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2546 | return false; |
| 2547 | } |
| 2548 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 2549 | return true; |
| 2550 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2551 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 2552 | bool ValidateGetPointervRobustANGLERobustANGLE(Context *context, |
| 2553 | GLenum pname, |
| 2554 | GLsizei bufSize, |
| 2555 | GLsizei *length, |
| 2556 | void **params) |
| 2557 | { |
| 2558 | UNIMPLEMENTED(); |
| 2559 | return false; |
| 2560 | } |
| 2561 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2562 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 2563 | GLint srcX0, |
| 2564 | GLint srcY0, |
| 2565 | GLint srcX1, |
| 2566 | GLint srcY1, |
| 2567 | GLint dstX0, |
| 2568 | GLint dstY0, |
| 2569 | GLint dstX1, |
| 2570 | GLint dstY1, |
| 2571 | GLbitfield mask, |
| 2572 | GLenum filter) |
| 2573 | { |
| 2574 | if (!context->getExtensions().framebufferBlit) |
| 2575 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2576 | context->validationError(GL_INVALID_OPERATION, kErrorBlitExtensionNotAvailable); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2577 | return false; |
| 2578 | } |
| 2579 | |
| 2580 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 2581 | { |
| 2582 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2583 | context->validationError(GL_INVALID_OPERATION, kErrorBlitExtensionScaleOrFlip); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2584 | return false; |
| 2585 | } |
| 2586 | |
| 2587 | if (filter == GL_LINEAR) |
| 2588 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2589 | context->validationError(GL_INVALID_ENUM, kErrorBlitExtensionLinear); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2590 | return false; |
| 2591 | } |
| 2592 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2593 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2594 | Framebuffer *drawFramebuffer = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2595 | |
| 2596 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2597 | { |
| 2598 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 2599 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 2600 | |
| 2601 | if (readColorAttachment && drawColorAttachment) |
| 2602 | { |
| 2603 | if (!(readColorAttachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2604 | readColorAttachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2605 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 2606 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2607 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2608 | context->validationError(GL_INVALID_OPERATION, |
| 2609 | kErrorBlitExtensionFromInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2610 | return false; |
| 2611 | } |
| 2612 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2613 | for (size_t drawbufferIdx = 0; |
| 2614 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2615 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2616 | const FramebufferAttachment *attachment = |
| 2617 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2618 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2619 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2620 | if (!(attachment->type() == GL_TEXTURE && |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2621 | attachment->getTextureImageIndex().getType() == TextureType::_2D) && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2622 | attachment->type() != GL_RENDERBUFFER && |
| 2623 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 2624 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2625 | context->validationError(GL_INVALID_OPERATION, |
| 2626 | kErrorBlitExtensionToInvalidAttachmentType); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2627 | return false; |
| 2628 | } |
| 2629 | |
| 2630 | // Return an error if the destination formats do not match |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 2631 | if (!Format::EquivalentForBlit(attachment->getFormat(), |
| 2632 | readColorAttachment->getFormat())) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2633 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2634 | context->validationError(GL_INVALID_OPERATION, |
| 2635 | kErrorBlitExtensionFormatMismatch); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2636 | return false; |
| 2637 | } |
| 2638 | } |
| 2639 | } |
| 2640 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2641 | GLint samples = readFramebuffer->getSamples(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2642 | if (samples != 0 && |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2643 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 2644 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 2645 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2646 | context->validationError(GL_INVALID_OPERATION, |
| 2647 | kErrorBlitExtensionMultisampledWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2648 | return false; |
| 2649 | } |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 2654 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2655 | for (size_t i = 0; i < 2; i++) |
| 2656 | { |
| 2657 | if (mask & masks[i]) |
| 2658 | { |
| 2659 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2660 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2661 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 2662 | drawFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2663 | |
| 2664 | if (readBuffer && drawBuffer) |
| 2665 | { |
| 2666 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 2667 | dstX0, dstY0, dstX1, dstY1)) |
| 2668 | { |
| 2669 | // only whole-buffer copies are permitted |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2670 | context->validationError(GL_INVALID_OPERATION, |
| 2671 | kErrorBlitExtensionDepthStencilWholeBufferBlit); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2672 | return false; |
| 2673 | } |
| 2674 | |
| 2675 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 2676 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2677 | context->validationError(GL_INVALID_OPERATION, |
| 2678 | kErrorBlitExtensionMultisampledDepthOrStencil); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2679 | return false; |
| 2680 | } |
| 2681 | } |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 2686 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2687 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2688 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2689 | bool ValidateClear(Context *context, GLbitfield mask) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2690 | { |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 2691 | Framebuffer *fbo = context->getGLState().getDrawFramebuffer(); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2692 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2693 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2694 | if (!ValidateFramebufferComplete(context, fbo)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2695 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2696 | return false; |
| 2697 | } |
| 2698 | |
| 2699 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 2700 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2701 | context->validationError(GL_INVALID_VALUE, kErrorInvalidClearMask); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2702 | return false; |
| 2703 | } |
| 2704 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2705 | if (extensions.webglCompatibility && (mask & GL_COLOR_BUFFER_BIT) != 0) |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2706 | { |
| 2707 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 2708 | GL_SIGNED_NORMALIZED}; |
| 2709 | |
Corentin Wallez | 59c4159 | 2017-07-11 13:19:54 -0400 | [diff] [blame] | 2710 | for (GLuint drawBufferIdx = 0; drawBufferIdx < fbo->getDrawbufferStateCount(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2711 | drawBufferIdx++) |
| 2712 | { |
| 2713 | if (!ValidateWebGLFramebufferAttachmentClearType( |
| 2714 | context, drawBufferIdx, validComponentTypes, ArraySize(validComponentTypes))) |
| 2715 | { |
| 2716 | return false; |
| 2717 | } |
| 2718 | } |
| 2719 | } |
| 2720 | |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2721 | if (extensions.multiview && extensions.disjointTimerQuery) |
| 2722 | { |
| 2723 | const State &state = context->getGLState(); |
| 2724 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2725 | if (framebuffer->getNumViews() > 1 && state.isQueryActive(QueryType::TimeElapsed)) |
| 2726 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2727 | context->validationError(GL_INVALID_OPERATION, |
| 2728 | "There is an active query for target " |
| 2729 | "GL_TIME_ELAPSED_EXT when the number of " |
| 2730 | "views in the active draw framebuffer is " |
| 2731 | "greater than 1."); |
Olli Etuaho | 94c91a9 | 2018-07-19 15:10:24 +0300 | [diff] [blame] | 2732 | return false; |
| 2733 | } |
| 2734 | } |
| 2735 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2736 | return true; |
| 2737 | } |
| 2738 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2739 | bool ValidateDrawBuffersEXT(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2740 | { |
| 2741 | if (!context->getExtensions().drawBuffers) |
| 2742 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2743 | context->validationError(GL_INVALID_OPERATION, "Extension not supported."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2744 | return false; |
| 2745 | } |
| 2746 | |
| 2747 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2748 | } |
| 2749 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2750 | bool ValidateTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2751 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2752 | GLint level, |
| 2753 | GLint internalformat, |
| 2754 | GLsizei width, |
| 2755 | GLsizei height, |
| 2756 | GLint border, |
| 2757 | GLenum format, |
| 2758 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2759 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2760 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2761 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2762 | { |
| 2763 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2764 | 0, 0, width, height, border, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2765 | } |
| 2766 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2767 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2768 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2769 | 0, 0, width, height, 1, border, format, type, -1, |
| 2770 | pixels); |
| 2771 | } |
| 2772 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 2773 | bool ValidateTexImage2DRobustANGLE(Context *context, |
| 2774 | TextureTarget target, |
| 2775 | GLint level, |
| 2776 | GLint internalformat, |
| 2777 | GLsizei width, |
| 2778 | GLsizei height, |
| 2779 | GLint border, |
| 2780 | GLenum format, |
| 2781 | GLenum type, |
| 2782 | GLsizei bufSize, |
| 2783 | const void *pixels) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2784 | { |
| 2785 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2786 | { |
| 2787 | return false; |
| 2788 | } |
| 2789 | |
| 2790 | if (context->getClientMajorVersion() < 3) |
| 2791 | { |
| 2792 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 2793 | 0, 0, width, height, border, format, type, bufSize, |
| 2794 | pixels); |
| 2795 | } |
| 2796 | |
| 2797 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2798 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 2799 | 0, 0, width, height, 1, border, format, type, bufSize, |
| 2800 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | bool ValidateTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2804 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2805 | GLint level, |
| 2806 | GLint xoffset, |
| 2807 | GLint yoffset, |
| 2808 | GLsizei width, |
| 2809 | GLsizei height, |
| 2810 | GLenum format, |
| 2811 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2812 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2813 | { |
| 2814 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2815 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2816 | { |
| 2817 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2818 | yoffset, width, height, 0, format, type, -1, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2819 | } |
| 2820 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2821 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2822 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2823 | yoffset, 0, width, height, 1, 0, format, type, -1, |
| 2824 | pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2825 | } |
| 2826 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2827 | bool ValidateTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2828 | TextureTarget target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2829 | GLint level, |
| 2830 | GLint xoffset, |
| 2831 | GLint yoffset, |
| 2832 | GLsizei width, |
| 2833 | GLsizei height, |
| 2834 | GLenum format, |
| 2835 | GLenum type, |
| 2836 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2837 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2838 | { |
| 2839 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2840 | { |
| 2841 | return false; |
| 2842 | } |
| 2843 | |
| 2844 | if (context->getClientMajorVersion() < 3) |
| 2845 | { |
| 2846 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2847 | yoffset, width, height, 0, format, type, bufSize, |
| 2848 | pixels); |
| 2849 | } |
| 2850 | |
| 2851 | ASSERT(context->getClientMajorVersion() >= 3); |
| 2852 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2853 | yoffset, 0, width, height, 1, 0, format, type, bufSize, |
| 2854 | pixels); |
| 2855 | } |
| 2856 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2857 | bool ValidateCompressedTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2858 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2859 | GLint level, |
| 2860 | GLenum internalformat, |
| 2861 | GLsizei width, |
| 2862 | GLsizei height, |
| 2863 | GLint border, |
| 2864 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2865 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2866 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2867 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2868 | { |
| 2869 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2870 | 0, width, height, border, GL_NONE, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2871 | { |
| 2872 | return false; |
| 2873 | } |
| 2874 | } |
| 2875 | else |
| 2876 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2877 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2878 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2879 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2880 | data)) |
| 2881 | { |
| 2882 | return false; |
| 2883 | } |
| 2884 | } |
| 2885 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2886 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2887 | |
| 2888 | GLuint blockSize = 0; |
| 2889 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2890 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2891 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2892 | return false; |
| 2893 | } |
| 2894 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2895 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2896 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2897 | context->validationError(GL_INVALID_VALUE, kErrorCompressedTextureDimensionsMustMatchData); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2898 | return false; |
| 2899 | } |
| 2900 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2901 | if (target == TextureTarget::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2902 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2903 | context->validationError(GL_INVALID_ENUM, |
| 2904 | "Rectangle texture cannot have a compressed format."); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2905 | return false; |
| 2906 | } |
| 2907 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2908 | return true; |
| 2909 | } |
| 2910 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2911 | bool ValidateCompressedTexImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2912 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2913 | GLint level, |
| 2914 | GLenum internalformat, |
| 2915 | GLsizei width, |
| 2916 | GLsizei height, |
| 2917 | GLint border, |
| 2918 | GLsizei imageSize, |
| 2919 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2920 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2921 | { |
| 2922 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2923 | { |
| 2924 | return false; |
| 2925 | } |
| 2926 | |
| 2927 | return ValidateCompressedTexImage2D(context, target, level, internalformat, width, height, |
| 2928 | border, imageSize, data); |
| 2929 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2930 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2931 | bool ValidateCompressedTexSubImage2DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2932 | TextureTarget target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2933 | GLint level, |
| 2934 | GLint xoffset, |
| 2935 | GLint yoffset, |
| 2936 | GLsizei width, |
| 2937 | GLsizei height, |
| 2938 | GLenum format, |
| 2939 | GLsizei imageSize, |
| 2940 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2941 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2942 | { |
| 2943 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2944 | { |
| 2945 | return false; |
| 2946 | } |
| 2947 | |
| 2948 | return ValidateCompressedTexSubImage2D(context, target, level, xoffset, yoffset, width, height, |
| 2949 | format, imageSize, data); |
| 2950 | } |
| 2951 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2952 | bool ValidateCompressedTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2953 | TextureTarget target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2954 | GLint level, |
| 2955 | GLint xoffset, |
| 2956 | GLint yoffset, |
| 2957 | GLsizei width, |
| 2958 | GLsizei height, |
| 2959 | GLenum format, |
| 2960 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2961 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2962 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2963 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2964 | { |
| 2965 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2966 | yoffset, width, height, 0, format, GL_NONE, -1, data)) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2967 | { |
| 2968 | return false; |
| 2969 | } |
| 2970 | } |
| 2971 | else |
| 2972 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2973 | ASSERT(context->getClientMajorVersion() >= 3); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2974 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2975 | yoffset, 0, width, height, 1, 0, format, GL_NONE, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2976 | data)) |
| 2977 | { |
| 2978 | return false; |
| 2979 | } |
| 2980 | } |
| 2981 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2982 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2983 | GLuint blockSize = 0; |
| 2984 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, 1), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2985 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2986 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2987 | return false; |
| 2988 | } |
| 2989 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2990 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2991 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 2992 | context->validationError(GL_INVALID_VALUE, kErrorInvalidCompressedImageSize); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2993 | return false; |
| 2994 | } |
| 2995 | |
| 2996 | return true; |
| 2997 | } |
| 2998 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2999 | bool ValidateGetBufferPointervOES(Context *context, |
| 3000 | BufferBinding target, |
| 3001 | GLenum pname, |
| 3002 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3003 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3004 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3005 | } |
| 3006 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3007 | bool ValidateMapBufferOES(Context *context, BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3008 | { |
| 3009 | if (!context->getExtensions().mapBuffer) |
| 3010 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3011 | context->validationError(GL_INVALID_OPERATION, "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3012 | return false; |
| 3013 | } |
| 3014 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3015 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3016 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3017 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3018 | return false; |
| 3019 | } |
| 3020 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3021 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3022 | |
| 3023 | if (buffer == nullptr) |
| 3024 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3025 | context->validationError(GL_INVALID_OPERATION, "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3026 | return false; |
| 3027 | } |
| 3028 | |
| 3029 | if (access != GL_WRITE_ONLY_OES) |
| 3030 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3031 | context->validationError(GL_INVALID_ENUM, "Non-write buffer mapping not supported."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3032 | return false; |
| 3033 | } |
| 3034 | |
| 3035 | if (buffer->isMapped()) |
| 3036 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3037 | context->validationError(GL_INVALID_OPERATION, "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3038 | return false; |
| 3039 | } |
| 3040 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3041 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3042 | } |
| 3043 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3044 | bool ValidateUnmapBufferOES(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3045 | { |
| 3046 | if (!context->getExtensions().mapBuffer) |
| 3047 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3048 | context->validationError(GL_INVALID_OPERATION, "Map buffer extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3049 | return false; |
| 3050 | } |
| 3051 | |
| 3052 | return ValidateUnmapBufferBase(context, target); |
| 3053 | } |
| 3054 | |
| 3055 | bool ValidateMapBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3056 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3057 | GLintptr offset, |
| 3058 | GLsizeiptr length, |
| 3059 | GLbitfield access) |
| 3060 | { |
| 3061 | if (!context->getExtensions().mapBufferRange) |
| 3062 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3063 | context->validationError(GL_INVALID_OPERATION, "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3064 | return false; |
| 3065 | } |
| 3066 | |
| 3067 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 3068 | } |
| 3069 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3070 | bool ValidateMapBufferBase(Context *context, BufferBinding target) |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3071 | { |
| 3072 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 3073 | ASSERT(buffer != nullptr); |
| 3074 | |
| 3075 | // Check if this buffer is currently being used as a transform feedback output buffer |
| 3076 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
| 3077 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 3078 | { |
| 3079 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 3080 | { |
| 3081 | const auto &transformFeedbackBuffer = transformFeedback->getIndexedBuffer(i); |
| 3082 | if (transformFeedbackBuffer.get() == buffer) |
| 3083 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3084 | context->validationError(GL_INVALID_OPERATION, |
| 3085 | "Buffer is currently bound for transform feedback."); |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3086 | return false; |
| 3087 | } |
| 3088 | } |
| 3089 | } |
| 3090 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3091 | if (context->getExtensions().webglCompatibility && |
| 3092 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3093 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3094 | context->validationError(GL_INVALID_OPERATION, kErrorBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3095 | return false; |
| 3096 | } |
| 3097 | |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3098 | return true; |
| 3099 | } |
| 3100 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3101 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3102 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3103 | GLintptr offset, |
| 3104 | GLsizeiptr length) |
| 3105 | { |
| 3106 | if (!context->getExtensions().mapBufferRange) |
| 3107 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3108 | context->validationError(GL_INVALID_OPERATION, "Map buffer range extension not available."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3109 | return false; |
| 3110 | } |
| 3111 | |
| 3112 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 3113 | } |
| 3114 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3115 | bool ValidateBindTexture(Context *context, TextureType target, GLuint texture) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3116 | { |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 3117 | if (!context->getStateCache().isValidBindTextureType(target)) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3118 | { |
Jamie Madill | ac66f98 | 2018-10-09 18:30:01 -0400 | [diff] [blame] | 3119 | RecordBindTextureTypeError(context, target); |
| 3120 | return false; |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3121 | } |
| 3122 | |
Jamie Madill | 0fdb956 | 2018-09-17 17:18:43 -0400 | [diff] [blame] | 3123 | if (texture == 0) |
| 3124 | { |
| 3125 | return true; |
| 3126 | } |
| 3127 | |
| 3128 | Texture *textureObject = context->getTexture(texture); |
| 3129 | if (textureObject && textureObject->getType() != target) |
| 3130 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3131 | context->validationError(GL_INVALID_OPERATION, kErrorTypeMismatch); |
Jamie Madill | 0fdb956 | 2018-09-17 17:18:43 -0400 | [diff] [blame] | 3132 | return false; |
| 3133 | } |
| 3134 | |
| 3135 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 3136 | !context->isTextureGenerated(texture)) |
| 3137 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3138 | context->validationError(GL_INVALID_OPERATION, "Texture was not generated"); |
Jamie Madill | 0fdb956 | 2018-09-17 17:18:43 -0400 | [diff] [blame] | 3139 | return false; |
| 3140 | } |
| 3141 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 3142 | return true; |
| 3143 | } |
| 3144 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3145 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 3146 | GLuint program, |
| 3147 | GLint location, |
| 3148 | const GLchar *name) |
| 3149 | { |
| 3150 | if (!context->getExtensions().bindUniformLocation) |
| 3151 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3152 | context->validationError(GL_INVALID_OPERATION, |
| 3153 | "GL_CHROMIUM_bind_uniform_location is not available."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3154 | return false; |
| 3155 | } |
| 3156 | |
| 3157 | Program *programObject = GetValidProgram(context, program); |
| 3158 | if (!programObject) |
| 3159 | { |
| 3160 | return false; |
| 3161 | } |
| 3162 | |
| 3163 | if (location < 0) |
| 3164 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3165 | context->validationError(GL_INVALID_VALUE, "Location cannot be less than 0."); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3166 | return false; |
| 3167 | } |
| 3168 | |
| 3169 | const Caps &caps = context->getCaps(); |
| 3170 | if (static_cast<size_t>(location) >= |
| 3171 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 3172 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3173 | context->validationError(GL_INVALID_VALUE, |
| 3174 | "Location must be less than " |
| 3175 | "(MAX_VERTEX_UNIFORM_VECTORS + " |
| 3176 | "MAX_FRAGMENT_UNIFORM_VECTORS) * 4"); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3177 | return false; |
| 3178 | } |
| 3179 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3180 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 3181 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 3182 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3183 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3184 | context->validationError(GL_INVALID_VALUE, kErrorInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 3185 | return false; |
| 3186 | } |
| 3187 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3188 | if (strncmp(name, "gl_", 3) == 0) |
| 3189 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3190 | context->validationError(GL_INVALID_VALUE, kErrorNameBeginsWithGL); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 3191 | return false; |
| 3192 | } |
| 3193 | |
| 3194 | return true; |
| 3195 | } |
| 3196 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3197 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3198 | { |
| 3199 | if (!context->getExtensions().framebufferMixedSamples) |
| 3200 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3201 | context->validationError(GL_INVALID_OPERATION, |
| 3202 | "GL_CHROMIUM_framebuffer_mixed_samples is not available."); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 3203 | return false; |
| 3204 | } |
| 3205 | switch (components) |
| 3206 | { |
| 3207 | case GL_RGB: |
| 3208 | case GL_RGBA: |
| 3209 | case GL_ALPHA: |
| 3210 | case GL_NONE: |
| 3211 | break; |
| 3212 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3213 | context->validationError( |
| 3214 | GL_INVALID_ENUM, |
| 3215 | "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] | 3216 | return false; |
| 3217 | } |
| 3218 | |
| 3219 | return true; |
| 3220 | } |
| 3221 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3222 | // CHROMIUM_path_rendering |
| 3223 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3224 | bool ValidateMatrixLoadfCHROMIUM(Context *context, GLenum matrixMode, const GLfloat *matrix) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3225 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3226 | if (!ValidateMatrixMode(context, matrixMode)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3227 | { |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3228 | return false; |
| 3229 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3230 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3231 | if (matrix == nullptr) |
| 3232 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3233 | context->validationError(GL_INVALID_OPERATION, "Invalid matrix."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3234 | return false; |
| 3235 | } |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3236 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3237 | return true; |
| 3238 | } |
| 3239 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3240 | bool ValidateMatrixLoadIdentityCHROMIUM(Context *context, GLenum matrixMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3241 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3242 | return ValidateMatrixMode(context, matrixMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3243 | } |
| 3244 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3245 | bool ValidateGenPathsCHROMIUM(Context *context, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3246 | { |
| 3247 | if (!context->getExtensions().pathRendering) |
| 3248 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3249 | context->validationError(GL_INVALID_OPERATION, |
| 3250 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3251 | return false; |
| 3252 | } |
| 3253 | |
| 3254 | // range = 0 is undefined in NV_path_rendering. |
| 3255 | // we add stricter semantic check here and require a non zero positive range. |
| 3256 | if (range <= 0) |
| 3257 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3258 | context->validationError(GL_INVALID_VALUE, kErrorInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3259 | return false; |
| 3260 | } |
| 3261 | |
| 3262 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range)) |
| 3263 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3264 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3265 | return false; |
| 3266 | } |
| 3267 | |
| 3268 | return true; |
| 3269 | } |
| 3270 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3271 | bool ValidateDeletePathsCHROMIUM(Context *context, GLuint path, GLsizei range) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3272 | { |
| 3273 | if (!context->getExtensions().pathRendering) |
| 3274 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3275 | context->validationError(GL_INVALID_OPERATION, |
| 3276 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3277 | return false; |
| 3278 | } |
| 3279 | |
| 3280 | // range = 0 is undefined in NV_path_rendering. |
| 3281 | // we add stricter semantic check here and require a non zero positive range. |
| 3282 | if (range <= 0) |
| 3283 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3284 | context->validationError(GL_INVALID_VALUE, kErrorInvalidRange); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3285 | return false; |
| 3286 | } |
| 3287 | |
| 3288 | angle::CheckedNumeric<std::uint32_t> checkedRange(path); |
| 3289 | checkedRange += range; |
| 3290 | |
| 3291 | if (!angle::IsValueInRangeForNumericType<std::uint32_t>(range) || !checkedRange.IsValid()) |
| 3292 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3293 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3294 | return false; |
| 3295 | } |
| 3296 | return true; |
| 3297 | } |
| 3298 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3299 | bool ValidatePathCommandsCHROMIUM(Context *context, |
| 3300 | GLuint path, |
| 3301 | GLsizei numCommands, |
| 3302 | const GLubyte *commands, |
| 3303 | GLsizei numCoords, |
| 3304 | GLenum coordType, |
| 3305 | const void *coords) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3306 | { |
| 3307 | if (!context->getExtensions().pathRendering) |
| 3308 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3309 | context->validationError(GL_INVALID_OPERATION, |
| 3310 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3311 | return false; |
| 3312 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3313 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3314 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3315 | context->validationError(GL_INVALID_OPERATION, kErrorNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3316 | return false; |
| 3317 | } |
| 3318 | |
| 3319 | if (numCommands < 0) |
| 3320 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3321 | context->validationError(GL_INVALID_VALUE, "Invalid number of commands."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3322 | return false; |
| 3323 | } |
| 3324 | else if (numCommands > 0) |
| 3325 | { |
| 3326 | if (!commands) |
| 3327 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3328 | context->validationError(GL_INVALID_VALUE, "No commands array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3329 | return false; |
| 3330 | } |
| 3331 | } |
| 3332 | |
| 3333 | if (numCoords < 0) |
| 3334 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3335 | context->validationError(GL_INVALID_VALUE, "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3336 | return false; |
| 3337 | } |
| 3338 | else if (numCoords > 0) |
| 3339 | { |
| 3340 | if (!coords) |
| 3341 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3342 | context->validationError(GL_INVALID_VALUE, "No coordinate array given."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3343 | return false; |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | std::uint32_t coordTypeSize = 0; |
| 3348 | switch (coordType) |
| 3349 | { |
| 3350 | case GL_BYTE: |
| 3351 | coordTypeSize = sizeof(GLbyte); |
| 3352 | break; |
| 3353 | |
| 3354 | case GL_UNSIGNED_BYTE: |
| 3355 | coordTypeSize = sizeof(GLubyte); |
| 3356 | break; |
| 3357 | |
| 3358 | case GL_SHORT: |
| 3359 | coordTypeSize = sizeof(GLshort); |
| 3360 | break; |
| 3361 | |
| 3362 | case GL_UNSIGNED_SHORT: |
| 3363 | coordTypeSize = sizeof(GLushort); |
| 3364 | break; |
| 3365 | |
| 3366 | case GL_FLOAT: |
| 3367 | coordTypeSize = sizeof(GLfloat); |
| 3368 | break; |
| 3369 | |
| 3370 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3371 | context->validationError(GL_INVALID_ENUM, "Invalid coordinate type."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3372 | return false; |
| 3373 | } |
| 3374 | |
| 3375 | angle::CheckedNumeric<std::uint32_t> checkedSize(numCommands); |
| 3376 | checkedSize += (coordTypeSize * numCoords); |
| 3377 | if (!checkedSize.IsValid()) |
| 3378 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3379 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3380 | return false; |
| 3381 | } |
| 3382 | |
| 3383 | // early return skips command data validation when it doesn't exist. |
| 3384 | if (!commands) |
| 3385 | return true; |
| 3386 | |
| 3387 | GLsizei expectedNumCoords = 0; |
| 3388 | for (GLsizei i = 0; i < numCommands; ++i) |
| 3389 | { |
| 3390 | switch (commands[i]) |
| 3391 | { |
| 3392 | case GL_CLOSE_PATH_CHROMIUM: // no coordinates. |
| 3393 | break; |
| 3394 | case GL_MOVE_TO_CHROMIUM: |
| 3395 | case GL_LINE_TO_CHROMIUM: |
| 3396 | expectedNumCoords += 2; |
| 3397 | break; |
| 3398 | case GL_QUADRATIC_CURVE_TO_CHROMIUM: |
| 3399 | expectedNumCoords += 4; |
| 3400 | break; |
| 3401 | case GL_CUBIC_CURVE_TO_CHROMIUM: |
| 3402 | expectedNumCoords += 6; |
| 3403 | break; |
| 3404 | case GL_CONIC_CURVE_TO_CHROMIUM: |
| 3405 | expectedNumCoords += 5; |
| 3406 | break; |
| 3407 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3408 | context->validationError(GL_INVALID_ENUM, "Invalid command."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3409 | return false; |
| 3410 | } |
| 3411 | } |
| 3412 | if (expectedNumCoords != numCoords) |
| 3413 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3414 | context->validationError(GL_INVALID_VALUE, "Invalid number of coordinates."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3415 | return false; |
| 3416 | } |
| 3417 | |
| 3418 | return true; |
| 3419 | } |
| 3420 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3421 | bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3422 | { |
| 3423 | if (!context->getExtensions().pathRendering) |
| 3424 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3425 | context->validationError(GL_INVALID_OPERATION, |
| 3426 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3427 | return false; |
| 3428 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3429 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3430 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3431 | context->validationError(GL_INVALID_OPERATION, kErrorNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3432 | return false; |
| 3433 | } |
| 3434 | |
| 3435 | switch (pname) |
| 3436 | { |
| 3437 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3438 | if (value < 0.0f) |
| 3439 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3440 | context->validationError(GL_INVALID_VALUE, "Invalid stroke width."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3441 | return false; |
| 3442 | } |
| 3443 | break; |
| 3444 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3445 | switch (static_cast<GLenum>(value)) |
| 3446 | { |
| 3447 | case GL_FLAT_CHROMIUM: |
| 3448 | case GL_SQUARE_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 end caps."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3453 | return false; |
| 3454 | } |
| 3455 | break; |
| 3456 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3457 | switch (static_cast<GLenum>(value)) |
| 3458 | { |
| 3459 | case GL_MITER_REVERT_CHROMIUM: |
| 3460 | case GL_BEVEL_CHROMIUM: |
| 3461 | case GL_ROUND_CHROMIUM: |
| 3462 | break; |
| 3463 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3464 | context->validationError(GL_INVALID_ENUM, "Invalid join style."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3465 | return false; |
| 3466 | } |
Nico Weber | 41b072b | 2018-02-09 10:01:32 -0500 | [diff] [blame] | 3467 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3468 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3469 | if (value < 0.0f) |
| 3470 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3471 | context->validationError(GL_INVALID_VALUE, "Invalid miter limit."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3472 | return false; |
| 3473 | } |
| 3474 | break; |
| 3475 | |
| 3476 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3477 | // no errors, only clamping. |
| 3478 | break; |
| 3479 | |
| 3480 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3481 | context->validationError(GL_INVALID_ENUM, "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3482 | return false; |
| 3483 | } |
| 3484 | return true; |
| 3485 | } |
| 3486 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3487 | bool ValidatePathParameteriCHROMIUM(Context *context, GLuint path, GLenum pname, GLint value) |
| 3488 | { |
| 3489 | // TODO(jmadill): Use proper clamping cast. |
| 3490 | return ValidatePathParameterfCHROMIUM(context, path, pname, static_cast<GLfloat>(value)); |
| 3491 | } |
| 3492 | |
| 3493 | bool ValidateGetPathParameterfvCHROMIUM(Context *context, GLuint path, GLenum pname, GLfloat *value) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3494 | { |
| 3495 | if (!context->getExtensions().pathRendering) |
| 3496 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3497 | context->validationError(GL_INVALID_OPERATION, |
| 3498 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3499 | return false; |
| 3500 | } |
| 3501 | |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3502 | if (!context->isPathGenerated(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3503 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3504 | context->validationError(GL_INVALID_OPERATION, kErrorNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3505 | return false; |
| 3506 | } |
| 3507 | if (!value) |
| 3508 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3509 | context->validationError(GL_INVALID_VALUE, "No value array."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3510 | return false; |
| 3511 | } |
| 3512 | |
| 3513 | switch (pname) |
| 3514 | { |
| 3515 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 3516 | case GL_PATH_END_CAPS_CHROMIUM: |
| 3517 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 3518 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 3519 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 3520 | break; |
| 3521 | |
| 3522 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3523 | context->validationError(GL_INVALID_ENUM, "Invalid path parameter."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3524 | return false; |
| 3525 | } |
| 3526 | |
| 3527 | return true; |
| 3528 | } |
| 3529 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3530 | bool ValidateGetPathParameterivCHROMIUM(Context *context, GLuint path, GLenum pname, GLint *value) |
| 3531 | { |
| 3532 | return ValidateGetPathParameterfvCHROMIUM(context, path, pname, |
| 3533 | reinterpret_cast<GLfloat *>(value)); |
| 3534 | } |
| 3535 | |
| 3536 | bool ValidatePathStencilFuncCHROMIUM(Context *context, GLenum func, GLint ref, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3537 | { |
| 3538 | if (!context->getExtensions().pathRendering) |
| 3539 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3540 | context->validationError(GL_INVALID_OPERATION, |
| 3541 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3542 | return false; |
| 3543 | } |
| 3544 | |
| 3545 | switch (func) |
| 3546 | { |
| 3547 | case GL_NEVER: |
| 3548 | case GL_ALWAYS: |
| 3549 | case GL_LESS: |
| 3550 | case GL_LEQUAL: |
| 3551 | case GL_EQUAL: |
| 3552 | case GL_GEQUAL: |
| 3553 | case GL_GREATER: |
| 3554 | case GL_NOTEQUAL: |
| 3555 | break; |
| 3556 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3557 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3558 | return false; |
| 3559 | } |
| 3560 | |
| 3561 | return true; |
| 3562 | } |
| 3563 | |
| 3564 | // Note that the spec specifies that for the path drawing commands |
| 3565 | // if the path object is not an existing path object the command |
| 3566 | // does nothing and no error is generated. |
| 3567 | // However if the path object exists but has not been specified any |
| 3568 | // commands then an error is generated. |
| 3569 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3570 | bool ValidateStencilFillPathCHROMIUM(Context *context, GLuint path, GLenum fillMode, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3571 | { |
| 3572 | if (!context->getExtensions().pathRendering) |
| 3573 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3574 | context->validationError(GL_INVALID_OPERATION, |
| 3575 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3576 | return false; |
| 3577 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3578 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3579 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3580 | context->validationError(GL_INVALID_OPERATION, kErrorNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3581 | return false; |
| 3582 | } |
| 3583 | |
| 3584 | switch (fillMode) |
| 3585 | { |
| 3586 | case GL_COUNT_UP_CHROMIUM: |
| 3587 | case GL_COUNT_DOWN_CHROMIUM: |
| 3588 | break; |
| 3589 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3590 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFillMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3591 | return false; |
| 3592 | } |
| 3593 | |
| 3594 | if (!isPow2(mask + 1)) |
| 3595 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3596 | context->validationError(GL_INVALID_VALUE, kErrorInvalidStencilBitMask); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3597 | return false; |
| 3598 | } |
| 3599 | |
| 3600 | return true; |
| 3601 | } |
| 3602 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3603 | bool ValidateStencilStrokePathCHROMIUM(Context *context, GLuint path, GLint reference, GLuint mask) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3604 | { |
| 3605 | if (!context->getExtensions().pathRendering) |
| 3606 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3607 | context->validationError(GL_INVALID_OPERATION, |
| 3608 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3609 | return false; |
| 3610 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3611 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3612 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3613 | 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] | 3614 | return false; |
| 3615 | } |
| 3616 | |
| 3617 | return true; |
| 3618 | } |
| 3619 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3620 | bool ValidateCoverPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3621 | { |
| 3622 | if (!context->getExtensions().pathRendering) |
| 3623 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3624 | context->validationError(GL_INVALID_OPERATION, |
| 3625 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3626 | return false; |
| 3627 | } |
Brandon Jones | 5977080 | 2018-04-02 13:18:42 -0700 | [diff] [blame] | 3628 | if (context->isPathGenerated(path) && !context->isPath(path)) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3629 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3630 | context->validationError(GL_INVALID_OPERATION, kErrorNoSuchPath); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3631 | return false; |
| 3632 | } |
| 3633 | |
| 3634 | switch (coverMode) |
| 3635 | { |
| 3636 | case GL_CONVEX_HULL_CHROMIUM: |
| 3637 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3638 | break; |
| 3639 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3640 | context->validationError(GL_INVALID_ENUM, kErrorInvalidCoverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3641 | return false; |
| 3642 | } |
| 3643 | return true; |
| 3644 | } |
| 3645 | |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 3646 | bool ValidateCoverFillPathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3647 | { |
| 3648 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3649 | } |
| 3650 | |
| 3651 | bool ValidateCoverStrokePathCHROMIUM(Context *context, GLuint path, GLenum coverMode) |
| 3652 | { |
| 3653 | return ValidateCoverPathCHROMIUM(context, path, coverMode); |
| 3654 | } |
| 3655 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3656 | bool ValidateStencilThenCoverFillPathCHROMIUM(Context *context, |
| 3657 | GLuint path, |
| 3658 | GLenum fillMode, |
| 3659 | GLuint mask, |
| 3660 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3661 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3662 | return ValidateStencilFillPathCHROMIUM(context, path, fillMode, mask) && |
| 3663 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3664 | } |
| 3665 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3666 | bool ValidateStencilThenCoverStrokePathCHROMIUM(Context *context, |
| 3667 | GLuint path, |
| 3668 | GLint reference, |
| 3669 | GLuint mask, |
| 3670 | GLenum coverMode) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3671 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3672 | return ValidateStencilStrokePathCHROMIUM(context, path, reference, mask) && |
| 3673 | ValidateCoverPathCHROMIUM(context, path, coverMode); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3674 | } |
| 3675 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3676 | bool ValidateIsPathCHROMIUM(Context *context, GLuint path) |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3677 | { |
| 3678 | if (!context->getExtensions().pathRendering) |
| 3679 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3680 | context->validationError(GL_INVALID_OPERATION, |
| 3681 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 3682 | return false; |
| 3683 | } |
| 3684 | return true; |
| 3685 | } |
| 3686 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3687 | bool ValidateCoverFillPathInstancedCHROMIUM(Context *context, |
| 3688 | GLsizei numPaths, |
| 3689 | GLenum pathNameType, |
| 3690 | const void *paths, |
| 3691 | GLuint pathBase, |
| 3692 | GLenum coverMode, |
| 3693 | GLenum transformType, |
| 3694 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3695 | { |
| 3696 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3697 | transformType, transformValues)) |
| 3698 | return false; |
| 3699 | |
| 3700 | switch (coverMode) |
| 3701 | { |
| 3702 | case GL_CONVEX_HULL_CHROMIUM: |
| 3703 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3704 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3705 | break; |
| 3706 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3707 | context->validationError(GL_INVALID_ENUM, kErrorInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3708 | return false; |
| 3709 | } |
| 3710 | |
| 3711 | return true; |
| 3712 | } |
| 3713 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3714 | bool ValidateCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3715 | GLsizei numPaths, |
| 3716 | GLenum pathNameType, |
| 3717 | const void *paths, |
| 3718 | GLuint pathBase, |
| 3719 | GLenum coverMode, |
| 3720 | GLenum transformType, |
| 3721 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3722 | { |
| 3723 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3724 | transformType, transformValues)) |
| 3725 | return false; |
| 3726 | |
| 3727 | switch (coverMode) |
| 3728 | { |
| 3729 | case GL_CONVEX_HULL_CHROMIUM: |
| 3730 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3731 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3732 | break; |
| 3733 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3734 | context->validationError(GL_INVALID_ENUM, kErrorInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3735 | return false; |
| 3736 | } |
| 3737 | |
| 3738 | return true; |
| 3739 | } |
| 3740 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3741 | bool ValidateStencilFillPathInstancedCHROMIUM(Context *context, |
| 3742 | GLsizei numPaths, |
| 3743 | GLenum pathNameType, |
| 3744 | const void *paths, |
| 3745 | GLuint pathBase, |
| 3746 | GLenum fillMode, |
| 3747 | GLuint mask, |
| 3748 | GLenum transformType, |
| 3749 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3750 | { |
| 3751 | |
| 3752 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3753 | transformType, transformValues)) |
| 3754 | return false; |
| 3755 | |
| 3756 | switch (fillMode) |
| 3757 | { |
| 3758 | case GL_COUNT_UP_CHROMIUM: |
| 3759 | case GL_COUNT_DOWN_CHROMIUM: |
| 3760 | break; |
| 3761 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3762 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3763 | return false; |
| 3764 | } |
| 3765 | if (!isPow2(mask + 1)) |
| 3766 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3767 | context->validationError(GL_INVALID_VALUE, kErrorInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3768 | return false; |
| 3769 | } |
| 3770 | return true; |
| 3771 | } |
| 3772 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3773 | bool ValidateStencilStrokePathInstancedCHROMIUM(Context *context, |
| 3774 | GLsizei numPaths, |
| 3775 | GLenum pathNameType, |
| 3776 | const void *paths, |
| 3777 | GLuint pathBase, |
| 3778 | GLint reference, |
| 3779 | GLuint mask, |
| 3780 | GLenum transformType, |
| 3781 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3782 | { |
| 3783 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3784 | transformType, transformValues)) |
| 3785 | return false; |
| 3786 | |
| 3787 | // no more validation here. |
| 3788 | |
| 3789 | return true; |
| 3790 | } |
| 3791 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3792 | bool ValidateStencilThenCoverFillPathInstancedCHROMIUM(Context *context, |
| 3793 | GLsizei numPaths, |
| 3794 | GLenum pathNameType, |
| 3795 | const void *paths, |
| 3796 | GLuint pathBase, |
| 3797 | GLenum fillMode, |
| 3798 | GLuint mask, |
| 3799 | GLenum coverMode, |
| 3800 | GLenum transformType, |
| 3801 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3802 | { |
| 3803 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3804 | transformType, transformValues)) |
| 3805 | return false; |
| 3806 | |
| 3807 | switch (coverMode) |
| 3808 | { |
| 3809 | case GL_CONVEX_HULL_CHROMIUM: |
| 3810 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3811 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3812 | break; |
| 3813 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3814 | context->validationError(GL_INVALID_ENUM, kErrorInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3815 | return false; |
| 3816 | } |
| 3817 | |
| 3818 | switch (fillMode) |
| 3819 | { |
| 3820 | case GL_COUNT_UP_CHROMIUM: |
| 3821 | case GL_COUNT_DOWN_CHROMIUM: |
| 3822 | break; |
| 3823 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3824 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFillMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3825 | return false; |
| 3826 | } |
| 3827 | if (!isPow2(mask + 1)) |
| 3828 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3829 | context->validationError(GL_INVALID_VALUE, kErrorInvalidStencilBitMask); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3830 | return false; |
| 3831 | } |
| 3832 | |
| 3833 | return true; |
| 3834 | } |
| 3835 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3836 | bool ValidateStencilThenCoverStrokePathInstancedCHROMIUM(Context *context, |
| 3837 | GLsizei numPaths, |
| 3838 | GLenum pathNameType, |
| 3839 | const void *paths, |
| 3840 | GLuint pathBase, |
| 3841 | GLint reference, |
| 3842 | GLuint mask, |
| 3843 | GLenum coverMode, |
| 3844 | GLenum transformType, |
| 3845 | const GLfloat *transformValues) |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3846 | { |
| 3847 | if (!ValidateInstancedPathParameters(context, numPaths, pathNameType, paths, pathBase, |
| 3848 | transformType, transformValues)) |
| 3849 | return false; |
| 3850 | |
| 3851 | switch (coverMode) |
| 3852 | { |
| 3853 | case GL_CONVEX_HULL_CHROMIUM: |
| 3854 | case GL_BOUNDING_BOX_CHROMIUM: |
| 3855 | case GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM: |
| 3856 | break; |
| 3857 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3858 | context->validationError(GL_INVALID_ENUM, kErrorInvalidCoverMode); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 3859 | return false; |
| 3860 | } |
| 3861 | |
| 3862 | return true; |
| 3863 | } |
| 3864 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3865 | bool ValidateBindFragmentInputLocationCHROMIUM(Context *context, |
| 3866 | GLuint program, |
| 3867 | GLint location, |
| 3868 | const GLchar *name) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3869 | { |
| 3870 | if (!context->getExtensions().pathRendering) |
| 3871 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3872 | context->validationError(GL_INVALID_OPERATION, |
| 3873 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3874 | return false; |
| 3875 | } |
| 3876 | |
| 3877 | const GLint MaxLocation = context->getCaps().maxVaryingVectors * 4; |
| 3878 | if (location >= MaxLocation) |
| 3879 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3880 | context->validationError(GL_INVALID_VALUE, "Location exceeds max varying."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3881 | return false; |
| 3882 | } |
| 3883 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3884 | const auto *programObject = context->getProgramNoResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3885 | if (!programObject) |
| 3886 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3887 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotBound); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3888 | return false; |
| 3889 | } |
| 3890 | |
| 3891 | if (!name) |
| 3892 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3893 | context->validationError(GL_INVALID_VALUE, "No name given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3894 | return false; |
| 3895 | } |
| 3896 | |
| 3897 | if (angle::BeginsWith(name, "gl_")) |
| 3898 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3899 | context->validationError(GL_INVALID_OPERATION, kErrorNameBeginsWithGL); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3900 | return false; |
| 3901 | } |
| 3902 | |
| 3903 | return true; |
| 3904 | } |
| 3905 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3906 | bool ValidateProgramPathFragmentInputGenCHROMIUM(Context *context, |
| 3907 | GLuint program, |
| 3908 | GLint location, |
| 3909 | GLenum genMode, |
| 3910 | GLint components, |
| 3911 | const GLfloat *coeffs) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3912 | { |
| 3913 | if (!context->getExtensions().pathRendering) |
| 3914 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3915 | context->validationError(GL_INVALID_OPERATION, |
| 3916 | "GL_CHROMIUM_path_rendering is not available."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3917 | return false; |
| 3918 | } |
| 3919 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3920 | const auto *programObject = context->getProgramResolveLink(program); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3921 | if (!programObject || programObject->isFlaggedForDeletion()) |
| 3922 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3923 | context->validationError(GL_INVALID_OPERATION, kErrorProgramDoesNotExist); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3924 | return false; |
| 3925 | } |
| 3926 | |
| 3927 | if (!programObject->isLinked()) |
| 3928 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3929 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3930 | return false; |
| 3931 | } |
| 3932 | |
| 3933 | switch (genMode) |
| 3934 | { |
| 3935 | case GL_NONE: |
| 3936 | if (components != 0) |
| 3937 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3938 | context->validationError(GL_INVALID_VALUE, "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3939 | return false; |
| 3940 | } |
| 3941 | break; |
| 3942 | |
| 3943 | case GL_OBJECT_LINEAR_CHROMIUM: |
| 3944 | case GL_EYE_LINEAR_CHROMIUM: |
| 3945 | case GL_CONSTANT_CHROMIUM: |
| 3946 | if (components < 1 || components > 4) |
| 3947 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3948 | context->validationError(GL_INVALID_VALUE, "Invalid components."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3949 | return false; |
| 3950 | } |
| 3951 | if (!coeffs) |
| 3952 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3953 | context->validationError(GL_INVALID_VALUE, "No coefficients array given."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3954 | return false; |
| 3955 | } |
| 3956 | break; |
| 3957 | |
| 3958 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3959 | context->validationError(GL_INVALID_ENUM, "Invalid gen mode."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3960 | return false; |
| 3961 | } |
| 3962 | |
| 3963 | // If the location is -1 then the command is silently ignored |
| 3964 | // and no further validation is needed. |
| 3965 | if (location == -1) |
| 3966 | return true; |
| 3967 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 3968 | const auto &binding = programObject->getFragmentInputBindingInfo(location); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3969 | |
| 3970 | if (!binding.valid) |
| 3971 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3972 | context->validationError(GL_INVALID_OPERATION, "No such binding."); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 3973 | return false; |
| 3974 | } |
| 3975 | |
| 3976 | if (binding.type != GL_NONE) |
| 3977 | { |
| 3978 | GLint expectedComponents = 0; |
| 3979 | switch (binding.type) |
| 3980 | { |
| 3981 | case GL_FLOAT: |
| 3982 | expectedComponents = 1; |
| 3983 | break; |
| 3984 | case GL_FLOAT_VEC2: |
| 3985 | expectedComponents = 2; |
| 3986 | break; |
| 3987 | case GL_FLOAT_VEC3: |
| 3988 | expectedComponents = 3; |
| 3989 | break; |
| 3990 | case GL_FLOAT_VEC4: |
| 3991 | expectedComponents = 4; |
| 3992 | break; |
| 3993 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 3994 | context->validationError( |
| 3995 | GL_INVALID_OPERATION, |
| 3996 | "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] | 3997 | return false; |
| 3998 | } |
| 3999 | if (expectedComponents != components && genMode != GL_NONE) |
| 4000 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4001 | context->validationError(GL_INVALID_OPERATION, "Unexpected number of components"); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 4002 | return false; |
| 4003 | } |
| 4004 | } |
| 4005 | return true; |
| 4006 | } |
| 4007 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4008 | bool ValidateCopyTextureCHROMIUM(Context *context, |
| 4009 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4010 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4011 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4012 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4013 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4014 | GLint internalFormat, |
| 4015 | GLenum destType, |
| 4016 | GLboolean unpackFlipY, |
| 4017 | GLboolean unpackPremultiplyAlpha, |
| 4018 | GLboolean unpackUnmultiplyAlpha) |
| 4019 | { |
| 4020 | if (!context->getExtensions().copyTexture) |
| 4021 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4022 | context->validationError(GL_INVALID_OPERATION, |
| 4023 | "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4024 | return false; |
| 4025 | } |
| 4026 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4027 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4028 | if (source == nullptr) |
| 4029 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4030 | 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] | 4031 | return false; |
| 4032 | } |
| 4033 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4034 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4035 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4036 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4037 | return false; |
| 4038 | } |
| 4039 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4040 | TextureType sourceType = source->getType(); |
| 4041 | ASSERT(sourceType != TextureType::CubeMap); |
| 4042 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4043 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4044 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4045 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4046 | context->validationError(GL_INVALID_VALUE, "Source texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4047 | return false; |
| 4048 | } |
| 4049 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4050 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 4051 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 4052 | if (sourceWidth == 0 || sourceHeight == 0) |
| 4053 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4054 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidInternalFormat); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4055 | return false; |
| 4056 | } |
| 4057 | |
| 4058 | const InternalFormat &sourceFormat = *source->getFormat(sourceTarget, sourceLevel).info; |
| 4059 | if (!IsValidCopyTextureSourceInternalFormatEnum(sourceFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4060 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4061 | context->validationError(GL_INVALID_OPERATION, |
| 4062 | "Source texture internal format is invalid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4063 | return false; |
| 4064 | } |
| 4065 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4066 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4067 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4068 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4069 | return false; |
| 4070 | } |
| 4071 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4072 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4073 | if (dest == nullptr) |
| 4074 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4075 | context->validationError(GL_INVALID_VALUE, |
| 4076 | "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4077 | return false; |
| 4078 | } |
| 4079 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4080 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4081 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4082 | context->validationError(GL_INVALID_VALUE, "Destination texture a valid texture type."); |
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 (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, sourceWidth, |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4087 | sourceHeight, false)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4088 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4089 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
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 (!IsValidCopyTextureDestinationFormatType(context, internalFormat, destType)) |
| 4094 | { |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4095 | return false; |
| 4096 | } |
| 4097 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4098 | if (dest->getType() == TextureType::CubeMap && sourceWidth != sourceHeight) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4099 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4100 | context->validationError( |
| 4101 | 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] | 4102 | return false; |
| 4103 | } |
| 4104 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4105 | if (dest->getImmutableFormat()) |
| 4106 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4107 | context->validationError(GL_INVALID_OPERATION, "Destination texture is immutable."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4108 | return false; |
| 4109 | } |
| 4110 | |
| 4111 | return true; |
| 4112 | } |
| 4113 | |
| 4114 | bool ValidateCopySubTextureCHROMIUM(Context *context, |
| 4115 | GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4116 | GLint sourceLevel, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4117 | TextureTarget destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4118 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 4119 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4120 | GLint xoffset, |
| 4121 | GLint yoffset, |
| 4122 | GLint x, |
| 4123 | GLint y, |
| 4124 | GLsizei width, |
| 4125 | GLsizei height, |
| 4126 | GLboolean unpackFlipY, |
| 4127 | GLboolean unpackPremultiplyAlpha, |
| 4128 | GLboolean unpackUnmultiplyAlpha) |
| 4129 | { |
| 4130 | if (!context->getExtensions().copyTexture) |
| 4131 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4132 | context->validationError(GL_INVALID_OPERATION, |
| 4133 | "GL_CHROMIUM_copy_texture extension not available."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4134 | return false; |
| 4135 | } |
| 4136 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4137 | const Texture *source = context->getTexture(sourceId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4138 | if (source == nullptr) |
| 4139 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4140 | 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] | 4141 | return false; |
| 4142 | } |
| 4143 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4144 | if (!IsValidCopyTextureSourceTarget(context, source->getType())) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4145 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4146 | context->validationError(GL_INVALID_VALUE, "Source texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4147 | return false; |
| 4148 | } |
| 4149 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4150 | TextureType sourceType = source->getType(); |
| 4151 | ASSERT(sourceType != TextureType::CubeMap); |
| 4152 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4153 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4154 | if (!IsValidCopyTextureSourceLevel(context, sourceType, sourceLevel)) |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4155 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4156 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4157 | return false; |
| 4158 | } |
| 4159 | |
| 4160 | if (source->getWidth(sourceTarget, sourceLevel) == 0 || |
| 4161 | source->getHeight(sourceTarget, sourceLevel) == 0) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4162 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4163 | context->validationError(GL_INVALID_VALUE, |
| 4164 | "The source level of the source texture must be defined."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4165 | return false; |
| 4166 | } |
| 4167 | |
| 4168 | if (x < 0 || y < 0) |
| 4169 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4170 | context->validationError(GL_INVALID_VALUE, "x and y cannot be negative."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4171 | return false; |
| 4172 | } |
| 4173 | |
| 4174 | if (width < 0 || height < 0) |
| 4175 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4176 | context->validationError(GL_INVALID_VALUE, kErrorNegativeSize); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4177 | return false; |
| 4178 | } |
| 4179 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4180 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 4181 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4182 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4183 | context->validationError(GL_INVALID_VALUE, kErrorSourceTextureTooSmall); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4184 | return false; |
| 4185 | } |
| 4186 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4187 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 4188 | if (!IsValidCopySubTextureSourceInternalFormat(sourceFormat.info->internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4189 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4190 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidInternalFormat); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4191 | return false; |
| 4192 | } |
| 4193 | |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4194 | if (!IsValidCopyTextureDestinationTargetEnum(context, destTarget)) |
| 4195 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4196 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Geoff Lang | 63458a3 | 2017-10-30 15:16:53 -0400 | [diff] [blame] | 4197 | return false; |
| 4198 | } |
| 4199 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4200 | const Texture *dest = context->getTexture(destId); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4201 | if (dest == nullptr) |
| 4202 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4203 | context->validationError(GL_INVALID_VALUE, |
| 4204 | "Destination texture is not a valid texture object."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4205 | return false; |
| 4206 | } |
| 4207 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4208 | if (!IsValidCopyTextureDestinationTarget(context, dest->getType(), destTarget)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4209 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4210 | context->validationError(GL_INVALID_VALUE, "Destination texture a valid texture type."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4211 | return false; |
| 4212 | } |
| 4213 | |
Brandon Jones | 2878379 | 2018-03-05 09:37:32 -0800 | [diff] [blame] | 4214 | if (!IsValidCopyTextureDestinationLevel(context, dest->getType(), destLevel, width, height, |
| 4215 | true)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4216 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4217 | context->validationError(GL_INVALID_VALUE, "Destination texture level is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4218 | return false; |
| 4219 | } |
| 4220 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4221 | if (dest->getWidth(destTarget, destLevel) == 0 || dest->getHeight(destTarget, destLevel) == 0) |
| 4222 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4223 | context->validationError( |
| 4224 | GL_INVALID_OPERATION, |
| 4225 | "The destination level of the destination texture must be defined."); |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4226 | return false; |
| 4227 | } |
| 4228 | |
| 4229 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 4230 | if (!IsValidCopySubTextureDestionationInternalFormat(destFormat.internalFormat)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4231 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4232 | context->validationError(GL_INVALID_OPERATION, |
| 4233 | "Destination internal format and type combination is not valid."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4234 | return false; |
| 4235 | } |
| 4236 | |
| 4237 | if (xoffset < 0 || yoffset < 0) |
| 4238 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4239 | context->validationError(GL_INVALID_VALUE, kErrorNegativeOffset); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4240 | return false; |
| 4241 | } |
| 4242 | |
Geoff Lang | 4f0e003 | 2017-05-01 16:04:35 -0400 | [diff] [blame] | 4243 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 4244 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel)) |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4245 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4246 | context->validationError(GL_INVALID_VALUE, |
| 4247 | "Destination texture not large enough to copy to."); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 4248 | return false; |
| 4249 | } |
| 4250 | |
| 4251 | return true; |
| 4252 | } |
| 4253 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4254 | bool ValidateCompressedCopyTextureCHROMIUM(Context *context, GLuint sourceId, GLuint destId) |
| 4255 | { |
| 4256 | if (!context->getExtensions().copyCompressedTexture) |
| 4257 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4258 | context->validationError(GL_INVALID_OPERATION, |
| 4259 | "GL_CHROMIUM_copy_compressed_texture extension not available."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4260 | return false; |
| 4261 | } |
| 4262 | |
| 4263 | const gl::Texture *source = context->getTexture(sourceId); |
| 4264 | if (source == nullptr) |
| 4265 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4266 | 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] | 4267 | return false; |
| 4268 | } |
| 4269 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4270 | if (source->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4271 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4272 | 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] | 4273 | return false; |
| 4274 | } |
| 4275 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4276 | if (source->getWidth(TextureTarget::_2D, 0) == 0 || |
| 4277 | source->getHeight(TextureTarget::_2D, 0) == 0) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4278 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4279 | context->validationError(GL_INVALID_VALUE, "Source texture must level 0 defined."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4280 | return false; |
| 4281 | } |
| 4282 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4283 | const gl::Format &sourceFormat = source->getFormat(TextureTarget::_2D, 0); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4284 | if (!sourceFormat.info->compressed) |
| 4285 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4286 | context->validationError(GL_INVALID_OPERATION, |
| 4287 | "Source texture must have a compressed internal format."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4288 | return false; |
| 4289 | } |
| 4290 | |
| 4291 | const gl::Texture *dest = context->getTexture(destId); |
| 4292 | if (dest == nullptr) |
| 4293 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4294 | context->validationError(GL_INVALID_VALUE, |
| 4295 | "Destination texture is not a valid texture object."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4296 | return false; |
| 4297 | } |
| 4298 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 4299 | if (dest->getType() != TextureType::_2D) |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4300 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4301 | context->validationError(GL_INVALID_VALUE, |
| 4302 | "Destination texture must be of type GL_TEXTURE_2D."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4303 | return false; |
| 4304 | } |
| 4305 | |
| 4306 | if (dest->getImmutableFormat()) |
| 4307 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4308 | context->validationError(GL_INVALID_OPERATION, "Destination cannot be immutable."); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 4309 | return false; |
| 4310 | } |
| 4311 | |
| 4312 | return true; |
| 4313 | } |
| 4314 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4315 | bool ValidateCreateShader(Context *context, ShaderType type) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4316 | { |
| 4317 | switch (type) |
| 4318 | { |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4319 | case ShaderType::Vertex: |
| 4320 | case ShaderType::Fragment: |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4321 | break; |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4322 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4323 | case ShaderType::Compute: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4324 | if (context->getClientVersion() < Version(3, 1)) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4325 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4326 | context->validationError(GL_INVALID_ENUM, kErrorES31Required); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4327 | return false; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4328 | } |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 4329 | break; |
| 4330 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4331 | case ShaderType::Geometry: |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4332 | if (!context->getExtensions().geometryShader) |
| 4333 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4334 | context->validationError(GL_INVALID_ENUM, kErrorInvalidShaderType); |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 4335 | return false; |
| 4336 | } |
| 4337 | break; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4338 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4339 | context->validationError(GL_INVALID_ENUM, kErrorInvalidShaderType); |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4340 | return false; |
| 4341 | } |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4342 | |
| 4343 | return true; |
| 4344 | } |
| 4345 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4346 | bool ValidateBufferData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4347 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4348 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4349 | const void *data, |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4350 | BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4351 | { |
| 4352 | if (size < 0) |
| 4353 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4354 | context->validationError(GL_INVALID_VALUE, kErrorNegativeSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4355 | return false; |
| 4356 | } |
| 4357 | |
| 4358 | switch (usage) |
| 4359 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4360 | case BufferUsage::StreamDraw: |
| 4361 | case BufferUsage::StaticDraw: |
| 4362 | case BufferUsage::DynamicDraw: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4363 | break; |
| 4364 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4365 | case BufferUsage::StreamRead: |
| 4366 | case BufferUsage::StaticRead: |
| 4367 | case BufferUsage::DynamicRead: |
| 4368 | case BufferUsage::StreamCopy: |
| 4369 | case BufferUsage::StaticCopy: |
| 4370 | case BufferUsage::DynamicCopy: |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4371 | if (context->getClientMajorVersion() < 3) |
| 4372 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4373 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4374 | return false; |
| 4375 | } |
| 4376 | break; |
| 4377 | |
| 4378 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4379 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferUsage); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4380 | return false; |
| 4381 | } |
| 4382 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4383 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4384 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4385 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4386 | return false; |
| 4387 | } |
| 4388 | |
| 4389 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4390 | |
| 4391 | if (!buffer) |
| 4392 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4393 | context->validationError(GL_INVALID_OPERATION, kErrorBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4394 | return false; |
| 4395 | } |
| 4396 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4397 | if (context->getExtensions().webglCompatibility && |
| 4398 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4399 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4400 | context->validationError(GL_INVALID_OPERATION, kErrorBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4401 | return false; |
| 4402 | } |
| 4403 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4404 | return true; |
| 4405 | } |
| 4406 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4407 | bool ValidateBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4408 | BufferBinding target, |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4409 | GLintptr offset, |
| 4410 | GLsizeiptr size, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4411 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4412 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4413 | if (size < 0) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4414 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4415 | context->validationError(GL_INVALID_VALUE, kErrorNegativeSize); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4416 | return false; |
| 4417 | } |
| 4418 | |
| 4419 | if (offset < 0) |
| 4420 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4421 | context->validationError(GL_INVALID_VALUE, kErrorNegativeOffset); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4422 | return false; |
| 4423 | } |
| 4424 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4425 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4426 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4427 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferTypes); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4428 | return false; |
| 4429 | } |
| 4430 | |
| 4431 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4432 | |
| 4433 | if (!buffer) |
| 4434 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4435 | context->validationError(GL_INVALID_OPERATION, kErrorBufferNotBound); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4436 | return false; |
| 4437 | } |
| 4438 | |
| 4439 | if (buffer->isMapped()) |
| 4440 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4441 | context->validationError(GL_INVALID_OPERATION, kErrorBufferMapped); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4442 | return false; |
| 4443 | } |
| 4444 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4445 | if (context->getExtensions().webglCompatibility && |
| 4446 | buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 4447 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4448 | context->validationError(GL_INVALID_OPERATION, kErrorBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 4449 | return false; |
| 4450 | } |
| 4451 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4452 | // Check for possible overflow of size + offset |
| 4453 | angle::CheckedNumeric<size_t> checkedSize(size); |
| 4454 | checkedSize += offset; |
| 4455 | if (!checkedSize.IsValid()) |
| 4456 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4457 | context->validationError(GL_INVALID_VALUE, kErrorParamOverflow); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4458 | return false; |
| 4459 | } |
| 4460 | |
| 4461 | if (size + offset > buffer->getSize()) |
| 4462 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4463 | context->validationError(GL_INVALID_VALUE, kErrorInsufficientBufferSize); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 4464 | return false; |
| 4465 | } |
| 4466 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 4467 | return true; |
| 4468 | } |
| 4469 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4470 | bool ValidateRequestExtensionANGLE(Context *context, const GLchar *name) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4471 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4472 | if (!context->getExtensions().requestExtension) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4473 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4474 | context->validationError(GL_INVALID_OPERATION, |
| 4475 | "GL_ANGLE_request_extension is not available."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4476 | return false; |
| 4477 | } |
| 4478 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 4479 | if (!context->isExtensionRequestable(name)) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4480 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4481 | context->validationError(GL_INVALID_OPERATION, "Extension is not requestable."); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 4482 | return false; |
| 4483 | } |
| 4484 | |
| 4485 | return true; |
| 4486 | } |
| 4487 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4488 | bool ValidateActiveTexture(Context *context, GLenum texture) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4489 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 4490 | if (context->getClientMajorVersion() < 2) |
| 4491 | { |
| 4492 | return ValidateMultitextureUnit(context, texture); |
| 4493 | } |
| 4494 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4495 | if (texture < GL_TEXTURE0 || |
| 4496 | texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) |
| 4497 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4498 | context->validationError(GL_INVALID_ENUM, kErrorInvalidCombinedImageUnit); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4499 | return false; |
| 4500 | } |
| 4501 | |
| 4502 | return true; |
| 4503 | } |
| 4504 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4505 | bool ValidateAttachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4506 | { |
| 4507 | Program *programObject = GetValidProgram(context, program); |
| 4508 | if (!programObject) |
| 4509 | { |
| 4510 | return false; |
| 4511 | } |
| 4512 | |
| 4513 | Shader *shaderObject = GetValidShader(context, shader); |
| 4514 | if (!shaderObject) |
| 4515 | { |
| 4516 | return false; |
| 4517 | } |
| 4518 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4519 | if (programObject->getAttachedShader(shaderObject->getType())) |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4520 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4521 | context->validationError(GL_INVALID_OPERATION, kErrorShaderAttachmentHasShader); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4522 | return false; |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | return true; |
| 4526 | } |
| 4527 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4528 | bool ValidateBindAttribLocation(Context *context, GLuint program, GLuint index, const GLchar *name) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4529 | { |
| 4530 | if (index >= MAX_VERTEX_ATTRIBS) |
| 4531 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4532 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxVertexAttribute); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4533 | return false; |
| 4534 | } |
| 4535 | |
| 4536 | if (strncmp(name, "gl_", 3) == 0) |
| 4537 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4538 | context->validationError(GL_INVALID_OPERATION, kErrorNameBeginsWithGL); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4539 | return false; |
| 4540 | } |
| 4541 | |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4542 | if (context->isWebGL()) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4543 | { |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4544 | const size_t length = strlen(name); |
| 4545 | |
| 4546 | if (!IsValidESSLString(name, length)) |
| 4547 | { |
| 4548 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters |
| 4549 | // for shader-related entry points |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4550 | context->validationError(GL_INVALID_VALUE, kErrorInvalidNameCharacters); |
Brandon Jones | ed5b46f | 2017-07-21 08:39:17 -0700 | [diff] [blame] | 4551 | return false; |
| 4552 | } |
| 4553 | |
| 4554 | if (!ValidateWebGLNameLength(context, length) || !ValidateWebGLNamePrefix(context, name)) |
| 4555 | { |
| 4556 | return false; |
| 4557 | } |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 4558 | } |
| 4559 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4560 | return GetValidProgram(context, program) != nullptr; |
| 4561 | } |
| 4562 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4563 | bool ValidateBindFramebuffer(Context *context, GLenum target, GLuint framebuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4564 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4565 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4566 | { |
Jamie Madill | a139f01 | 2018-10-10 16:13:03 -0400 | [diff] [blame] | 4567 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFramebufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4568 | return false; |
| 4569 | } |
| 4570 | |
| 4571 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4572 | !context->isFramebufferGenerated(framebuffer)) |
| 4573 | { |
Jamie Madill | a139f01 | 2018-10-10 16:13:03 -0400 | [diff] [blame] | 4574 | context->validationError(GL_INVALID_OPERATION, kErrorObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4575 | return false; |
| 4576 | } |
| 4577 | |
| 4578 | return true; |
| 4579 | } |
| 4580 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4581 | bool ValidateBindRenderbuffer(Context *context, GLenum target, GLuint renderbuffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4582 | { |
| 4583 | if (target != GL_RENDERBUFFER) |
| 4584 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4585 | context->validationError(GL_INVALID_ENUM, kErrorInvalidRenderbufferTarget); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4586 | return false; |
| 4587 | } |
| 4588 | |
| 4589 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 4590 | !context->isRenderbufferGenerated(renderbuffer)) |
| 4591 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4592 | context->validationError(GL_INVALID_OPERATION, kErrorObjectNotGenerated); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4593 | return false; |
| 4594 | } |
| 4595 | |
| 4596 | return true; |
| 4597 | } |
| 4598 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4599 | static bool ValidBlendEquationMode(const Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4600 | { |
| 4601 | switch (mode) |
| 4602 | { |
| 4603 | case GL_FUNC_ADD: |
| 4604 | case GL_FUNC_SUBTRACT: |
| 4605 | case GL_FUNC_REVERSE_SUBTRACT: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4606 | return true; |
| 4607 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4608 | case GL_MIN: |
| 4609 | case GL_MAX: |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4610 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().blendMinMax; |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4611 | |
| 4612 | default: |
| 4613 | return false; |
| 4614 | } |
| 4615 | } |
| 4616 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4617 | bool ValidateBlendColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4618 | { |
| 4619 | return true; |
| 4620 | } |
| 4621 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4622 | bool ValidateBlendEquation(Context *context, GLenum mode) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4623 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4624 | if (!ValidBlendEquationMode(context, mode)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4625 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4626 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4627 | return false; |
| 4628 | } |
| 4629 | |
| 4630 | return true; |
| 4631 | } |
| 4632 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4633 | bool ValidateBlendEquationSeparate(Context *context, GLenum modeRGB, GLenum modeAlpha) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4634 | { |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4635 | if (!ValidBlendEquationMode(context, modeRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4636 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4637 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4638 | return false; |
| 4639 | } |
| 4640 | |
Geoff Lang | 50cac57 | 2017-09-26 17:37:43 -0400 | [diff] [blame] | 4641 | if (!ValidBlendEquationMode(context, modeAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4642 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4643 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBlendEquation); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4644 | return false; |
| 4645 | } |
| 4646 | |
| 4647 | return true; |
| 4648 | } |
| 4649 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4650 | bool ValidateBlendFunc(Context *context, GLenum sfactor, GLenum dfactor) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4651 | { |
| 4652 | return ValidateBlendFuncSeparate(context, sfactor, dfactor, sfactor, dfactor); |
| 4653 | } |
| 4654 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4655 | bool ValidateBlendFuncSeparate(Context *context, |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4656 | GLenum srcRGB, |
| 4657 | GLenum dstRGB, |
| 4658 | GLenum srcAlpha, |
| 4659 | GLenum dstAlpha) |
| 4660 | { |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4661 | if (!ValidSrcBlendFunc(context, srcRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4662 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4663 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBlendFunction); |
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, dstRGB)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4668 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4669 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4670 | return false; |
| 4671 | } |
| 4672 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4673 | if (!ValidSrcBlendFunc(context, srcAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4674 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4675 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4676 | return false; |
| 4677 | } |
| 4678 | |
Olli Etuaho | ab5fb5e | 2018-09-18 17:23:28 +0300 | [diff] [blame] | 4679 | if (!ValidDstBlendFunc(context, dstAlpha)) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4680 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4681 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBlendFunction); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4682 | return false; |
| 4683 | } |
| 4684 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4685 | if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc || |
| 4686 | context->getExtensions().webglCompatibility) |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4687 | { |
| 4688 | bool constantColorUsed = |
| 4689 | (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || |
| 4690 | dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR); |
| 4691 | |
| 4692 | bool constantAlphaUsed = |
| 4693 | (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA || |
| 4694 | dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 4695 | |
| 4696 | if (constantColorUsed && constantAlphaUsed) |
| 4697 | { |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4698 | const char *msg; |
| 4699 | if (context->getExtensions().webglCompatibility) |
| 4700 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4701 | msg = kErrorInvalidConstantColor; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4702 | } |
| 4703 | else |
| 4704 | { |
| 4705 | msg = |
| 4706 | "Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and " |
| 4707 | "GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR not supported by this " |
| 4708 | "implementation."; |
Jamie Madill | a2f043d | 2018-07-10 17:21:20 -0400 | [diff] [blame] | 4709 | WARN() << msg; |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 4710 | } |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4711 | context->validationError(GL_INVALID_OPERATION, msg); |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 4712 | return false; |
| 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | return true; |
| 4717 | } |
| 4718 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4719 | bool ValidateGetString(Context *context, GLenum name) |
| 4720 | { |
| 4721 | switch (name) |
| 4722 | { |
| 4723 | case GL_VENDOR: |
| 4724 | case GL_RENDERER: |
| 4725 | case GL_VERSION: |
| 4726 | case GL_SHADING_LANGUAGE_VERSION: |
| 4727 | case GL_EXTENSIONS: |
| 4728 | break; |
| 4729 | |
| 4730 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 4731 | if (!context->getExtensions().requestExtension) |
| 4732 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4733 | context->validationError(GL_INVALID_ENUM, kErrorInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4734 | return false; |
| 4735 | } |
| 4736 | break; |
| 4737 | |
| 4738 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4739 | context->validationError(GL_INVALID_ENUM, kErrorInvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 4740 | return false; |
| 4741 | } |
| 4742 | |
| 4743 | return true; |
| 4744 | } |
| 4745 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4746 | bool ValidateLineWidth(Context *context, GLfloat width) |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4747 | { |
| 4748 | if (width <= 0.0f || isNaN(width)) |
| 4749 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4750 | context->validationError(GL_INVALID_VALUE, kErrorInvalidWidth); |
Geoff Lang | 47c4808 | 2016-12-07 15:38:13 -0500 | [diff] [blame] | 4751 | return false; |
| 4752 | } |
| 4753 | |
| 4754 | return true; |
| 4755 | } |
| 4756 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4757 | bool ValidateVertexAttribPointer(Context *context, |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4758 | GLuint index, |
| 4759 | GLint size, |
| 4760 | GLenum type, |
| 4761 | GLboolean normalized, |
| 4762 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4763 | const void *ptr) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4764 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4765 | if (!ValidateVertexFormatBase(context, index, size, type, false)) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4766 | { |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4767 | return false; |
| 4768 | } |
| 4769 | |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4770 | if (stride < 0) |
| 4771 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4772 | context->validationError(GL_INVALID_VALUE, kErrorNegativeStride); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4773 | return false; |
| 4774 | } |
| 4775 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4776 | const Caps &caps = context->getCaps(); |
| 4777 | if (context->getClientVersion() >= ES_3_1) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4778 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4779 | if (stride > caps.maxVertexAttribStride) |
| 4780 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4781 | context->validationError(GL_INVALID_VALUE, |
| 4782 | "stride cannot be greater than MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4783 | return false; |
| 4784 | } |
| 4785 | |
| 4786 | if (index >= caps.maxVertexAttribBindings) |
| 4787 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4788 | context->validationError(GL_INVALID_VALUE, |
| 4789 | "index must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4790 | return false; |
| 4791 | } |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | // [OpenGL ES 3.0.2] Section 2.8 page 24: |
| 4795 | // An INVALID_OPERATION error is generated when a non-zero vertex array object |
| 4796 | // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point, |
| 4797 | // and the pointer argument is not NULL. |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 4798 | bool nullBufferAllowed = context->getGLState().areClientArraysEnabled() && |
| 4799 | context->getGLState().getVertexArray()->id() == 0; |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4800 | if (!nullBufferAllowed && context->getGLState().getTargetBuffer(BufferBinding::Array) == 0 && |
| 4801 | ptr != nullptr) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4802 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4803 | context->validationError( |
| 4804 | GL_INVALID_OPERATION, |
| 4805 | "Client data cannot be used with a non-default vertex array object."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4806 | return false; |
| 4807 | } |
| 4808 | |
| 4809 | if (context->getExtensions().webglCompatibility) |
| 4810 | { |
| 4811 | // WebGL 1.0 [Section 6.14] Fixed point support |
| 4812 | // The WebGL API does not support the GL_FIXED data type. |
| 4813 | if (type == GL_FIXED) |
| 4814 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4815 | context->validationError(GL_INVALID_ENUM, "GL_FIXED is not supported in WebGL."); |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4816 | return false; |
| 4817 | } |
| 4818 | |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 4819 | if (!ValidateWebGLVertexAttribPointer(context, type, normalized, stride, ptr, false)) |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4820 | { |
Corentin Wallez | 0c7baf1 | 2016-12-19 15:43:10 -0500 | [diff] [blame] | 4821 | return false; |
| 4822 | } |
| 4823 | } |
| 4824 | |
| 4825 | return true; |
| 4826 | } |
| 4827 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4828 | bool ValidateDepthRangef(Context *context, GLfloat zNear, GLfloat zFar) |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4829 | { |
| 4830 | if (context->getExtensions().webglCompatibility && zNear > zFar) |
| 4831 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4832 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidDepthRange); |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 4833 | return false; |
| 4834 | } |
| 4835 | |
| 4836 | return true; |
| 4837 | } |
| 4838 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4839 | bool ValidateRenderbufferStorage(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4840 | GLenum target, |
| 4841 | GLenum internalformat, |
| 4842 | GLsizei width, |
| 4843 | GLsizei height) |
| 4844 | { |
| 4845 | return ValidateRenderbufferStorageParametersBase(context, target, 0, internalformat, width, |
| 4846 | height); |
| 4847 | } |
| 4848 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4849 | bool ValidateRenderbufferStorageMultisampleANGLE(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4850 | GLenum target, |
| 4851 | GLsizei samples, |
| 4852 | GLenum internalformat, |
| 4853 | GLsizei width, |
| 4854 | GLsizei height) |
| 4855 | { |
| 4856 | if (!context->getExtensions().framebufferMultisample) |
| 4857 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4858 | context->validationError(GL_INVALID_OPERATION, |
| 4859 | "GL_ANGLE_framebuffer_multisample not available"); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4860 | return false; |
| 4861 | } |
| 4862 | |
| 4863 | // 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^] | 4864 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4865 | // generated. |
| 4866 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
| 4867 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4868 | context->validationError(GL_INVALID_VALUE, kErrorSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4869 | return false; |
| 4870 | } |
| 4871 | |
| 4872 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 4873 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 4874 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 4875 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 4876 | if (context->getClientMajorVersion() >= 3) |
| 4877 | { |
| 4878 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 4879 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 4880 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4881 | context->validationError(GL_OUT_OF_MEMORY, kErrorSamplesOutOfRange); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4882 | return false; |
| 4883 | } |
| 4884 | } |
| 4885 | |
| 4886 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 4887 | width, height); |
| 4888 | } |
| 4889 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4890 | bool ValidateCheckFramebufferStatus(Context *context, GLenum target) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4891 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4892 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4893 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4894 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFramebufferTarget); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4895 | return false; |
| 4896 | } |
| 4897 | |
| 4898 | return true; |
| 4899 | } |
| 4900 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4901 | bool ValidateClearColor(Context *context, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4902 | { |
| 4903 | return true; |
| 4904 | } |
| 4905 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4906 | bool ValidateClearDepthf(Context *context, GLfloat depth) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4907 | { |
| 4908 | return true; |
| 4909 | } |
| 4910 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4911 | bool ValidateClearStencil(Context *context, GLint s) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4912 | { |
| 4913 | return true; |
| 4914 | } |
| 4915 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4916 | bool ValidateColorMask(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4917 | GLboolean red, |
| 4918 | GLboolean green, |
| 4919 | GLboolean blue, |
| 4920 | GLboolean alpha) |
| 4921 | { |
| 4922 | return true; |
| 4923 | } |
| 4924 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4925 | bool ValidateCompileShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4926 | { |
| 4927 | return true; |
| 4928 | } |
| 4929 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4930 | bool ValidateCreateProgram(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4931 | { |
| 4932 | return true; |
| 4933 | } |
| 4934 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4935 | bool ValidateCullFace(Context *context, CullFaceMode mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4936 | { |
| 4937 | switch (mode) |
| 4938 | { |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 4939 | case CullFaceMode::Front: |
| 4940 | case CullFaceMode::Back: |
| 4941 | case CullFaceMode::FrontAndBack: |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4942 | break; |
| 4943 | |
| 4944 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4945 | context->validationError(GL_INVALID_ENUM, kErrorInvalidCullMode); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4946 | return false; |
| 4947 | } |
| 4948 | |
| 4949 | return true; |
| 4950 | } |
| 4951 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4952 | bool ValidateDeleteProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4953 | { |
| 4954 | if (program == 0) |
| 4955 | { |
| 4956 | return false; |
| 4957 | } |
| 4958 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4959 | if (!context->getProgramResolveLink(program)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4960 | { |
| 4961 | if (context->getShader(program)) |
| 4962 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4963 | context->validationError(GL_INVALID_OPERATION, kErrorExpectedProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4964 | return false; |
| 4965 | } |
| 4966 | else |
| 4967 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4968 | context->validationError(GL_INVALID_VALUE, kErrorInvalidProgramName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4969 | return false; |
| 4970 | } |
| 4971 | } |
| 4972 | |
| 4973 | return true; |
| 4974 | } |
| 4975 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4976 | bool ValidateDeleteShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4977 | { |
| 4978 | if (shader == 0) |
| 4979 | { |
| 4980 | return false; |
| 4981 | } |
| 4982 | |
| 4983 | if (!context->getShader(shader)) |
| 4984 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4985 | if (context->getProgramResolveLink(shader)) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4986 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4987 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4988 | return false; |
| 4989 | } |
| 4990 | else |
| 4991 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 4992 | context->validationError(GL_INVALID_VALUE, kErrorExpectedShaderName); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4993 | return false; |
| 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | return true; |
| 4998 | } |
| 4999 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5000 | bool ValidateDepthFunc(Context *context, GLenum func) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5001 | { |
| 5002 | switch (func) |
| 5003 | { |
| 5004 | case GL_NEVER: |
| 5005 | case GL_ALWAYS: |
| 5006 | case GL_LESS: |
| 5007 | case GL_LEQUAL: |
| 5008 | case GL_EQUAL: |
| 5009 | case GL_GREATER: |
| 5010 | case GL_GEQUAL: |
| 5011 | case GL_NOTEQUAL: |
| 5012 | break; |
| 5013 | |
| 5014 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5015 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5016 | return false; |
| 5017 | } |
| 5018 | |
| 5019 | return true; |
| 5020 | } |
| 5021 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5022 | bool ValidateDepthMask(Context *context, GLboolean flag) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5023 | { |
| 5024 | return true; |
| 5025 | } |
| 5026 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5027 | bool ValidateDetachShader(Context *context, GLuint program, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5028 | { |
| 5029 | Program *programObject = GetValidProgram(context, program); |
| 5030 | if (!programObject) |
| 5031 | { |
| 5032 | return false; |
| 5033 | } |
| 5034 | |
| 5035 | Shader *shaderObject = GetValidShader(context, shader); |
| 5036 | if (!shaderObject) |
| 5037 | { |
| 5038 | return false; |
| 5039 | } |
| 5040 | |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 5041 | const Shader *attachedShader = programObject->getAttachedShader(shaderObject->getType()); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5042 | if (attachedShader != shaderObject) |
| 5043 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5044 | context->validationError(GL_INVALID_OPERATION, kErrorShaderToDetachMustBeAttached); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5045 | return false; |
| 5046 | } |
| 5047 | |
| 5048 | return true; |
| 5049 | } |
| 5050 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5051 | bool ValidateDisableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5052 | { |
| 5053 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5054 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5055 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5056 | return false; |
| 5057 | } |
| 5058 | |
| 5059 | return true; |
| 5060 | } |
| 5061 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5062 | bool ValidateEnableVertexAttribArray(Context *context, GLuint index) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5063 | { |
| 5064 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5065 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5066 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxVertexAttribute); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5067 | return false; |
| 5068 | } |
| 5069 | |
| 5070 | return true; |
| 5071 | } |
| 5072 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5073 | bool ValidateFinish(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5074 | { |
| 5075 | return true; |
| 5076 | } |
| 5077 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5078 | bool ValidateFlush(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5079 | { |
| 5080 | return true; |
| 5081 | } |
| 5082 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5083 | bool ValidateFrontFace(Context *context, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5084 | { |
| 5085 | switch (mode) |
| 5086 | { |
| 5087 | case GL_CW: |
| 5088 | case GL_CCW: |
| 5089 | break; |
| 5090 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5091 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5092 | return false; |
| 5093 | } |
| 5094 | |
| 5095 | return true; |
| 5096 | } |
| 5097 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5098 | bool ValidateGetActiveAttrib(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5099 | GLuint program, |
| 5100 | GLuint index, |
| 5101 | GLsizei bufsize, |
| 5102 | GLsizei *length, |
| 5103 | GLint *size, |
| 5104 | GLenum *type, |
| 5105 | GLchar *name) |
| 5106 | { |
| 5107 | if (bufsize < 0) |
| 5108 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5109 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5110 | return false; |
| 5111 | } |
| 5112 | |
| 5113 | Program *programObject = GetValidProgram(context, program); |
| 5114 | |
| 5115 | if (!programObject) |
| 5116 | { |
| 5117 | return false; |
| 5118 | } |
| 5119 | |
| 5120 | if (index >= static_cast<GLuint>(programObject->getActiveAttributeCount())) |
| 5121 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5122 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5123 | return false; |
| 5124 | } |
| 5125 | |
| 5126 | return true; |
| 5127 | } |
| 5128 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5129 | bool ValidateGetActiveUniform(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5130 | GLuint program, |
| 5131 | GLuint index, |
| 5132 | GLsizei bufsize, |
| 5133 | GLsizei *length, |
| 5134 | GLint *size, |
| 5135 | GLenum *type, |
| 5136 | GLchar *name) |
| 5137 | { |
| 5138 | if (bufsize < 0) |
| 5139 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5140 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5141 | return false; |
| 5142 | } |
| 5143 | |
| 5144 | Program *programObject = GetValidProgram(context, program); |
| 5145 | |
| 5146 | if (!programObject) |
| 5147 | { |
| 5148 | return false; |
| 5149 | } |
| 5150 | |
| 5151 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 5152 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5153 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxActiveUniform); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5154 | return false; |
| 5155 | } |
| 5156 | |
| 5157 | return true; |
| 5158 | } |
| 5159 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5160 | bool ValidateGetAttachedShaders(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5161 | GLuint program, |
| 5162 | GLsizei maxcount, |
| 5163 | GLsizei *count, |
| 5164 | GLuint *shaders) |
| 5165 | { |
| 5166 | if (maxcount < 0) |
| 5167 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5168 | context->validationError(GL_INVALID_VALUE, kErrorNegativeMaxCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5169 | return false; |
| 5170 | } |
| 5171 | |
| 5172 | Program *programObject = GetValidProgram(context, program); |
| 5173 | |
| 5174 | if (!programObject) |
| 5175 | { |
| 5176 | return false; |
| 5177 | } |
| 5178 | |
| 5179 | return true; |
| 5180 | } |
| 5181 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5182 | bool ValidateGetAttribLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5183 | { |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5184 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5185 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5186 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5187 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5188 | context->validationError(GL_INVALID_VALUE, kErrorInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5189 | return false; |
| 5190 | } |
| 5191 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5192 | Program *programObject = GetValidProgram(context, program); |
| 5193 | |
| 5194 | if (!programObject) |
| 5195 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5196 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotBound); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5197 | return false; |
| 5198 | } |
| 5199 | |
| 5200 | if (!programObject->isLinked()) |
| 5201 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5202 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5203 | return false; |
| 5204 | } |
| 5205 | |
| 5206 | return true; |
| 5207 | } |
| 5208 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5209 | bool ValidateGetBooleanv(Context *context, GLenum pname, GLboolean *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 ValidateGetError(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5217 | { |
| 5218 | return true; |
| 5219 | } |
| 5220 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5221 | bool ValidateGetFloatv(Context *context, GLenum pname, GLfloat *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5222 | { |
| 5223 | GLenum nativeType; |
| 5224 | unsigned int numParams = 0; |
| 5225 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5226 | } |
| 5227 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5228 | bool ValidateGetIntegerv(Context *context, GLenum pname, GLint *params) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5229 | { |
| 5230 | GLenum nativeType; |
| 5231 | unsigned int numParams = 0; |
| 5232 | return ValidateStateQuery(context, pname, &nativeType, &numParams); |
| 5233 | } |
| 5234 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5235 | bool ValidateGetProgramInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5236 | GLuint program, |
| 5237 | GLsizei bufsize, |
| 5238 | GLsizei *length, |
| 5239 | GLchar *infolog) |
| 5240 | { |
| 5241 | if (bufsize < 0) |
| 5242 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5243 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5244 | return false; |
| 5245 | } |
| 5246 | |
| 5247 | Program *programObject = GetValidProgram(context, program); |
| 5248 | if (!programObject) |
| 5249 | { |
| 5250 | return false; |
| 5251 | } |
| 5252 | |
| 5253 | return true; |
| 5254 | } |
| 5255 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5256 | bool ValidateGetShaderInfoLog(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5257 | GLuint shader, |
| 5258 | GLsizei bufsize, |
| 5259 | GLsizei *length, |
| 5260 | GLchar *infolog) |
| 5261 | { |
| 5262 | if (bufsize < 0) |
| 5263 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5264 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5265 | return false; |
| 5266 | } |
| 5267 | |
| 5268 | Shader *shaderObject = GetValidShader(context, shader); |
| 5269 | if (!shaderObject) |
| 5270 | { |
| 5271 | return false; |
| 5272 | } |
| 5273 | |
| 5274 | return true; |
| 5275 | } |
| 5276 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5277 | bool ValidateGetShaderPrecisionFormat(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5278 | GLenum shadertype, |
| 5279 | GLenum precisiontype, |
| 5280 | GLint *range, |
| 5281 | GLint *precision) |
| 5282 | { |
| 5283 | switch (shadertype) |
| 5284 | { |
| 5285 | case GL_VERTEX_SHADER: |
| 5286 | case GL_FRAGMENT_SHADER: |
| 5287 | break; |
| 5288 | case GL_COMPUTE_SHADER: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5289 | context->validationError(GL_INVALID_OPERATION, |
| 5290 | "compute shader precision not yet implemented."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5291 | return false; |
| 5292 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5293 | context->validationError(GL_INVALID_ENUM, kErrorInvalidShaderType); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5294 | return false; |
| 5295 | } |
| 5296 | |
| 5297 | switch (precisiontype) |
| 5298 | { |
| 5299 | case GL_LOW_FLOAT: |
| 5300 | case GL_MEDIUM_FLOAT: |
| 5301 | case GL_HIGH_FLOAT: |
| 5302 | case GL_LOW_INT: |
| 5303 | case GL_MEDIUM_INT: |
| 5304 | case GL_HIGH_INT: |
| 5305 | break; |
| 5306 | |
| 5307 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5308 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPrecision); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5309 | return false; |
| 5310 | } |
| 5311 | |
| 5312 | return true; |
| 5313 | } |
| 5314 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5315 | bool ValidateGetShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5316 | GLuint shader, |
| 5317 | GLsizei bufsize, |
| 5318 | GLsizei *length, |
| 5319 | GLchar *source) |
| 5320 | { |
| 5321 | if (bufsize < 0) |
| 5322 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5323 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5324 | return false; |
| 5325 | } |
| 5326 | |
| 5327 | Shader *shaderObject = GetValidShader(context, shader); |
| 5328 | if (!shaderObject) |
| 5329 | { |
| 5330 | return false; |
| 5331 | } |
| 5332 | |
| 5333 | return true; |
| 5334 | } |
| 5335 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5336 | bool ValidateGetUniformLocation(Context *context, GLuint program, const GLchar *name) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5337 | { |
| 5338 | if (strstr(name, "gl_") == name) |
| 5339 | { |
| 5340 | return false; |
| 5341 | } |
| 5342 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5343 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5344 | // shader-related entry points |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5345 | if (context->getExtensions().webglCompatibility && !IsValidESSLString(name, strlen(name))) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5346 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5347 | context->validationError(GL_INVALID_VALUE, kErrorInvalidNameCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5348 | return false; |
| 5349 | } |
| 5350 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5351 | Program *programObject = GetValidProgram(context, program); |
| 5352 | |
| 5353 | if (!programObject) |
| 5354 | { |
| 5355 | return false; |
| 5356 | } |
| 5357 | |
| 5358 | if (!programObject->isLinked()) |
| 5359 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5360 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5361 | return false; |
| 5362 | } |
| 5363 | |
| 5364 | return true; |
| 5365 | } |
| 5366 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5367 | bool ValidateHint(Context *context, GLenum target, GLenum mode) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5368 | { |
| 5369 | switch (mode) |
| 5370 | { |
| 5371 | case GL_FASTEST: |
| 5372 | case GL_NICEST: |
| 5373 | case GL_DONT_CARE: |
| 5374 | break; |
| 5375 | |
| 5376 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5377 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5378 | return false; |
| 5379 | } |
| 5380 | |
| 5381 | switch (target) |
| 5382 | { |
| 5383 | case GL_GENERATE_MIPMAP_HINT: |
| 5384 | break; |
| 5385 | |
Geoff Lang | e7bd218 | 2017-06-16 16:13:13 -0400 | [diff] [blame] | 5386 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: |
| 5387 | if (context->getClientVersion() < ES_3_0 && |
| 5388 | !context->getExtensions().standardDerivatives) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5389 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5390 | context->validationError(GL_INVALID_ENUM, |
| 5391 | "hint requires OES_standard_derivatives."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5392 | return false; |
| 5393 | } |
| 5394 | break; |
| 5395 | |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5396 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 5397 | case GL_POINT_SMOOTH_HINT: |
| 5398 | case GL_LINE_SMOOTH_HINT: |
| 5399 | case GL_FOG_HINT: |
| 5400 | if (context->getClientMajorVersion() >= 2) |
| 5401 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5402 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 5403 | return false; |
| 5404 | } |
| 5405 | break; |
| 5406 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5407 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5408 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5409 | return false; |
| 5410 | } |
| 5411 | |
| 5412 | return true; |
| 5413 | } |
| 5414 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5415 | bool ValidateIsBuffer(Context *context, GLuint buffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5416 | { |
| 5417 | return true; |
| 5418 | } |
| 5419 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5420 | bool ValidateIsFramebuffer(Context *context, GLuint framebuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5421 | { |
| 5422 | return true; |
| 5423 | } |
| 5424 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5425 | bool ValidateIsProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5426 | { |
| 5427 | return true; |
| 5428 | } |
| 5429 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5430 | bool ValidateIsRenderbuffer(Context *context, GLuint renderbuffer) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5431 | { |
| 5432 | return true; |
| 5433 | } |
| 5434 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5435 | bool ValidateIsShader(Context *context, GLuint shader) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5436 | { |
| 5437 | return true; |
| 5438 | } |
| 5439 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5440 | bool ValidateIsTexture(Context *context, GLuint texture) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5441 | { |
| 5442 | return true; |
| 5443 | } |
| 5444 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5445 | bool ValidatePixelStorei(Context *context, GLenum pname, GLint param) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5446 | { |
| 5447 | if (context->getClientMajorVersion() < 3) |
| 5448 | { |
| 5449 | switch (pname) |
| 5450 | { |
| 5451 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5452 | case GL_UNPACK_SKIP_IMAGES: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5453 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5454 | return false; |
| 5455 | |
| 5456 | case GL_UNPACK_ROW_LENGTH: |
| 5457 | case GL_UNPACK_SKIP_ROWS: |
| 5458 | case GL_UNPACK_SKIP_PIXELS: |
| 5459 | if (!context->getExtensions().unpackSubimage) |
| 5460 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5461 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5462 | return false; |
| 5463 | } |
| 5464 | break; |
| 5465 | |
| 5466 | case GL_PACK_ROW_LENGTH: |
| 5467 | case GL_PACK_SKIP_ROWS: |
| 5468 | case GL_PACK_SKIP_PIXELS: |
| 5469 | if (!context->getExtensions().packSubimage) |
| 5470 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5471 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5472 | return false; |
| 5473 | } |
| 5474 | break; |
| 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | if (param < 0) |
| 5479 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5480 | context->validationError(GL_INVALID_VALUE, "Cannot use negative values in PixelStorei"); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5481 | return false; |
| 5482 | } |
| 5483 | |
| 5484 | switch (pname) |
| 5485 | { |
| 5486 | case GL_UNPACK_ALIGNMENT: |
| 5487 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5488 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5489 | context->validationError(GL_INVALID_VALUE, kErrorInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5490 | return false; |
| 5491 | } |
| 5492 | break; |
| 5493 | |
| 5494 | case GL_PACK_ALIGNMENT: |
| 5495 | if (param != 1 && param != 2 && param != 4 && param != 8) |
| 5496 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5497 | context->validationError(GL_INVALID_VALUE, kErrorInvalidUnpackAlignment); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5498 | return false; |
| 5499 | } |
| 5500 | break; |
| 5501 | |
| 5502 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5503 | if (!context->getExtensions().packReverseRowOrder) |
| 5504 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5505 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | 000dab8 | 2017-09-27 14:27:07 -0400 | [diff] [blame] | 5506 | } |
| 5507 | break; |
| 5508 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5509 | case GL_UNPACK_ROW_LENGTH: |
| 5510 | case GL_UNPACK_IMAGE_HEIGHT: |
| 5511 | case GL_UNPACK_SKIP_IMAGES: |
| 5512 | case GL_UNPACK_SKIP_ROWS: |
| 5513 | case GL_UNPACK_SKIP_PIXELS: |
| 5514 | case GL_PACK_ROW_LENGTH: |
| 5515 | case GL_PACK_SKIP_ROWS: |
| 5516 | case GL_PACK_SKIP_PIXELS: |
| 5517 | break; |
| 5518 | |
| 5519 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5520 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5521 | return false; |
| 5522 | } |
| 5523 | |
| 5524 | return true; |
| 5525 | } |
| 5526 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5527 | bool ValidatePolygonOffset(Context *context, GLfloat factor, GLfloat units) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5528 | { |
| 5529 | return true; |
| 5530 | } |
| 5531 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5532 | bool ValidateReleaseShaderCompiler(Context *context) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5533 | { |
| 5534 | return true; |
| 5535 | } |
| 5536 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5537 | bool ValidateSampleCoverage(Context *context, GLfloat value, GLboolean invert) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5538 | { |
| 5539 | return true; |
| 5540 | } |
| 5541 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5542 | bool ValidateScissor(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5543 | { |
| 5544 | if (width < 0 || height < 0) |
| 5545 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5546 | context->validationError(GL_INVALID_VALUE, kErrorNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5547 | return false; |
| 5548 | } |
| 5549 | |
| 5550 | return true; |
| 5551 | } |
| 5552 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5553 | bool ValidateShaderBinary(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5554 | GLsizei n, |
| 5555 | const GLuint *shaders, |
| 5556 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5557 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5558 | GLsizei length) |
| 5559 | { |
| 5560 | const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats; |
| 5561 | if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == |
| 5562 | shaderBinaryFormats.end()) |
| 5563 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5564 | context->validationError(GL_INVALID_ENUM, "Invalid shader binary format."); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5565 | return false; |
| 5566 | } |
| 5567 | |
| 5568 | return true; |
| 5569 | } |
| 5570 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5571 | bool ValidateShaderSource(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5572 | GLuint shader, |
| 5573 | GLsizei count, |
| 5574 | const GLchar *const *string, |
| 5575 | const GLint *length) |
| 5576 | { |
| 5577 | if (count < 0) |
| 5578 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5579 | context->validationError(GL_INVALID_VALUE, kErrorNegativeCount); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5580 | return false; |
| 5581 | } |
| 5582 | |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5583 | // The WebGL spec (section 6.20) disallows strings containing invalid ESSL characters for |
| 5584 | // shader-related entry points |
| 5585 | if (context->getExtensions().webglCompatibility) |
| 5586 | { |
| 5587 | for (GLsizei i = 0; i < count; i++) |
| 5588 | { |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5589 | size_t len = |
| 5590 | (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] | 5591 | |
| 5592 | // Backslash as line-continuation is allowed in WebGL 2.0. |
Geoff Lang | cab92ee | 2017-07-19 17:32:07 -0400 | [diff] [blame] | 5593 | if (!IsValidESSLShaderSourceString(string[i], len, |
| 5594 | context->getClientVersion() >= ES_3_0)) |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5595 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5596 | context->validationError(GL_INVALID_VALUE, kErrorShaderSourceInvalidCharacters); |
Geoff Lang | fc32e8b | 2017-05-31 14:16:59 -0400 | [diff] [blame] | 5597 | return false; |
| 5598 | } |
| 5599 | } |
| 5600 | } |
| 5601 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5602 | Shader *shaderObject = GetValidShader(context, shader); |
| 5603 | if (!shaderObject) |
| 5604 | { |
| 5605 | return false; |
| 5606 | } |
| 5607 | |
| 5608 | return true; |
| 5609 | } |
| 5610 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5611 | bool ValidateStencilFunc(Context *context, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5612 | { |
| 5613 | if (!IsValidStencilFunc(func)) |
| 5614 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5615 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5616 | return false; |
| 5617 | } |
| 5618 | |
| 5619 | return true; |
| 5620 | } |
| 5621 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5622 | bool ValidateStencilFuncSeparate(Context *context, GLenum face, GLenum func, GLint ref, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5623 | { |
| 5624 | if (!IsValidStencilFace(face)) |
| 5625 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5626 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5627 | return false; |
| 5628 | } |
| 5629 | |
| 5630 | if (!IsValidStencilFunc(func)) |
| 5631 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5632 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5633 | return false; |
| 5634 | } |
| 5635 | |
| 5636 | return true; |
| 5637 | } |
| 5638 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5639 | bool ValidateStencilMask(Context *context, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5640 | { |
| 5641 | return true; |
| 5642 | } |
| 5643 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5644 | bool ValidateStencilMaskSeparate(Context *context, GLenum face, GLuint mask) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5645 | { |
| 5646 | if (!IsValidStencilFace(face)) |
| 5647 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5648 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5649 | return false; |
| 5650 | } |
| 5651 | |
| 5652 | return true; |
| 5653 | } |
| 5654 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5655 | bool ValidateStencilOp(Context *context, GLenum fail, GLenum zfail, GLenum zpass) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5656 | { |
| 5657 | if (!IsValidStencilOp(fail)) |
| 5658 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5659 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5660 | return false; |
| 5661 | } |
| 5662 | |
| 5663 | if (!IsValidStencilOp(zfail)) |
| 5664 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5665 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5666 | return false; |
| 5667 | } |
| 5668 | |
| 5669 | if (!IsValidStencilOp(zpass)) |
| 5670 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5671 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5672 | return false; |
| 5673 | } |
| 5674 | |
| 5675 | return true; |
| 5676 | } |
| 5677 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5678 | bool ValidateStencilOpSeparate(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5679 | GLenum face, |
| 5680 | GLenum fail, |
| 5681 | GLenum zfail, |
| 5682 | GLenum zpass) |
| 5683 | { |
| 5684 | if (!IsValidStencilFace(face)) |
| 5685 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5686 | context->validationError(GL_INVALID_ENUM, kErrorInvalidStencil); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5687 | return false; |
| 5688 | } |
| 5689 | |
| 5690 | return ValidateStencilOp(context, fail, zfail, zpass); |
| 5691 | } |
| 5692 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5693 | bool ValidateUniform1f(Context *context, GLint location, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5694 | { |
| 5695 | return ValidateUniform(context, GL_FLOAT, location, 1); |
| 5696 | } |
| 5697 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5698 | bool ValidateUniform1fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5699 | { |
| 5700 | return ValidateUniform(context, GL_FLOAT, location, count); |
| 5701 | } |
| 5702 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5703 | bool ValidateUniform1i(Context *context, GLint location, GLint x) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5704 | { |
| 5705 | return ValidateUniform1iv(context, location, 1, &x); |
| 5706 | } |
| 5707 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5708 | bool ValidateUniform2fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5709 | { |
| 5710 | return ValidateUniform(context, GL_FLOAT_VEC2, location, count); |
| 5711 | } |
| 5712 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5713 | bool ValidateUniform2i(Context *context, GLint location, GLint x, GLint y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5714 | { |
| 5715 | return ValidateUniform(context, GL_INT_VEC2, location, 1); |
| 5716 | } |
| 5717 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5718 | bool ValidateUniform2iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5719 | { |
| 5720 | return ValidateUniform(context, GL_INT_VEC2, location, count); |
| 5721 | } |
| 5722 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5723 | bool ValidateUniform3f(Context *context, GLint location, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5724 | { |
| 5725 | return ValidateUniform(context, GL_FLOAT_VEC3, location, 1); |
| 5726 | } |
| 5727 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5728 | bool ValidateUniform3fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5729 | { |
| 5730 | return ValidateUniform(context, GL_FLOAT_VEC3, location, count); |
| 5731 | } |
| 5732 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5733 | bool ValidateUniform3i(Context *context, GLint location, GLint x, GLint y, GLint z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5734 | { |
| 5735 | return ValidateUniform(context, GL_INT_VEC3, location, 1); |
| 5736 | } |
| 5737 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5738 | bool ValidateUniform3iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5739 | { |
| 5740 | return ValidateUniform(context, GL_INT_VEC3, location, count); |
| 5741 | } |
| 5742 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5743 | 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] | 5744 | { |
| 5745 | return ValidateUniform(context, GL_FLOAT_VEC4, location, 1); |
| 5746 | } |
| 5747 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5748 | bool ValidateUniform4fv(Context *context, GLint location, GLsizei count, const GLfloat *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5749 | { |
| 5750 | return ValidateUniform(context, GL_FLOAT_VEC4, location, count); |
| 5751 | } |
| 5752 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5753 | 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] | 5754 | { |
| 5755 | return ValidateUniform(context, GL_INT_VEC4, location, 1); |
| 5756 | } |
| 5757 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5758 | bool ValidateUniform4iv(Context *context, GLint location, GLsizei count, const GLint *v) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5759 | { |
| 5760 | return ValidateUniform(context, GL_INT_VEC4, location, count); |
| 5761 | } |
| 5762 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5763 | bool ValidateUniformMatrix2fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5764 | GLint location, |
| 5765 | GLsizei count, |
| 5766 | GLboolean transpose, |
| 5767 | const GLfloat *value) |
| 5768 | { |
| 5769 | return ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose); |
| 5770 | } |
| 5771 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5772 | bool ValidateUniformMatrix3fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5773 | GLint location, |
| 5774 | GLsizei count, |
| 5775 | GLboolean transpose, |
| 5776 | const GLfloat *value) |
| 5777 | { |
| 5778 | return ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose); |
| 5779 | } |
| 5780 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5781 | bool ValidateUniformMatrix4fv(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5782 | GLint location, |
| 5783 | GLsizei count, |
| 5784 | GLboolean transpose, |
| 5785 | const GLfloat *value) |
| 5786 | { |
| 5787 | return ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose); |
| 5788 | } |
| 5789 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5790 | bool ValidateValidateProgram(Context *context, GLuint program) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5791 | { |
| 5792 | Program *programObject = GetValidProgram(context, program); |
| 5793 | |
| 5794 | if (!programObject) |
| 5795 | { |
| 5796 | return false; |
| 5797 | } |
| 5798 | |
| 5799 | return true; |
| 5800 | } |
| 5801 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5802 | bool ValidateVertexAttrib1f(Context *context, GLuint index, GLfloat x) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5803 | { |
| 5804 | return ValidateVertexAttribIndex(context, index); |
| 5805 | } |
| 5806 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5807 | bool ValidateVertexAttrib1fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5808 | { |
| 5809 | return ValidateVertexAttribIndex(context, index); |
| 5810 | } |
| 5811 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5812 | bool ValidateVertexAttrib2f(Context *context, GLuint index, GLfloat x, GLfloat y) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5813 | { |
| 5814 | return ValidateVertexAttribIndex(context, index); |
| 5815 | } |
| 5816 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5817 | bool ValidateVertexAttrib2fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5818 | { |
| 5819 | return ValidateVertexAttribIndex(context, index); |
| 5820 | } |
| 5821 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5822 | bool ValidateVertexAttrib3f(Context *context, GLuint index, GLfloat x, GLfloat y, GLfloat z) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5823 | { |
| 5824 | return ValidateVertexAttribIndex(context, index); |
| 5825 | } |
| 5826 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5827 | bool ValidateVertexAttrib3fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5828 | { |
| 5829 | return ValidateVertexAttribIndex(context, index); |
| 5830 | } |
| 5831 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5832 | bool ValidateVertexAttrib4f(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5833 | GLuint index, |
| 5834 | GLfloat x, |
| 5835 | GLfloat y, |
| 5836 | GLfloat z, |
| 5837 | GLfloat w) |
| 5838 | { |
| 5839 | return ValidateVertexAttribIndex(context, index); |
| 5840 | } |
| 5841 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5842 | bool ValidateVertexAttrib4fv(Context *context, GLuint index, const GLfloat *values) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5843 | { |
| 5844 | return ValidateVertexAttribIndex(context, index); |
| 5845 | } |
| 5846 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5847 | bool ValidateViewport(Context *context, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5848 | { |
| 5849 | if (width < 0 || height < 0) |
| 5850 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5851 | context->validationError(GL_INVALID_VALUE, kErrorViewportNegativeSize); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 5852 | return false; |
| 5853 | } |
| 5854 | |
| 5855 | return true; |
| 5856 | } |
| 5857 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5858 | bool ValidateDrawElements(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 5859 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5860 | GLsizei count, |
| 5861 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 5862 | const void *indices) |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 5863 | { |
| 5864 | return ValidateDrawElementsCommon(context, mode, count, type, indices, 1); |
| 5865 | } |
| 5866 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 5867 | bool ValidateGetFramebufferAttachmentParameteriv(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5868 | GLenum target, |
| 5869 | GLenum attachment, |
| 5870 | GLenum pname, |
| 5871 | GLint *params) |
| 5872 | { |
| 5873 | return ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 5874 | nullptr); |
| 5875 | } |
| 5876 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5877 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5878 | { |
| 5879 | return ValidateGetProgramivBase(context, program, pname, nullptr); |
| 5880 | } |
| 5881 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5882 | bool ValidateCopyTexImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5883 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5884 | GLint level, |
| 5885 | GLenum internalformat, |
| 5886 | GLint x, |
| 5887 | GLint y, |
| 5888 | GLsizei width, |
| 5889 | GLsizei height, |
| 5890 | GLint border) |
| 5891 | { |
| 5892 | if (context->getClientMajorVersion() < 3) |
| 5893 | { |
| 5894 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 5895 | 0, x, y, width, height, border); |
| 5896 | } |
| 5897 | |
| 5898 | ASSERT(context->getClientMajorVersion() == 3); |
| 5899 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 5900 | 0, x, y, width, height, border); |
| 5901 | } |
| 5902 | |
| 5903 | bool ValidateCopyTexSubImage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5904 | TextureTarget target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5905 | GLint level, |
| 5906 | GLint xoffset, |
| 5907 | GLint yoffset, |
| 5908 | GLint x, |
| 5909 | GLint y, |
| 5910 | GLsizei width, |
| 5911 | GLsizei height) |
| 5912 | { |
| 5913 | if (context->getClientMajorVersion() < 3) |
| 5914 | { |
| 5915 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 5916 | yoffset, x, y, width, height, 0); |
| 5917 | } |
| 5918 | |
| 5919 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 5920 | yoffset, 0, x, y, width, height, 0); |
| 5921 | } |
| 5922 | |
| 5923 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 5924 | { |
| 5925 | return ValidateGenOrDelete(context, n); |
| 5926 | } |
| 5927 | |
| 5928 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 5929 | { |
| 5930 | return ValidateGenOrDelete(context, n); |
| 5931 | } |
| 5932 | |
| 5933 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 5934 | { |
| 5935 | return ValidateGenOrDelete(context, n); |
| 5936 | } |
| 5937 | |
| 5938 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 5939 | { |
| 5940 | return ValidateGenOrDelete(context, n); |
| 5941 | } |
| 5942 | |
| 5943 | bool ValidateDisable(Context *context, GLenum cap) |
| 5944 | { |
| 5945 | if (!ValidCap(context, cap, false)) |
| 5946 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5947 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5948 | return false; |
| 5949 | } |
| 5950 | |
| 5951 | return true; |
| 5952 | } |
| 5953 | |
| 5954 | bool ValidateEnable(Context *context, GLenum cap) |
| 5955 | { |
| 5956 | if (!ValidCap(context, cap, false)) |
| 5957 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5958 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5959 | return false; |
| 5960 | } |
| 5961 | |
| 5962 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 5963 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 5964 | { |
| 5965 | const char *errorMessage = "Current renderer doesn't support alpha-to-coverage"; |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5966 | context->validationError(GL_INVALID_OPERATION, errorMessage); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5967 | |
| 5968 | // We also output an error message to the debugger window if tracing is active, so that |
| 5969 | // developers can see the error message. |
| 5970 | ERR() << errorMessage; |
| 5971 | return false; |
| 5972 | } |
| 5973 | |
| 5974 | return true; |
| 5975 | } |
| 5976 | |
| 5977 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 5978 | GLenum target, |
| 5979 | GLenum attachment, |
| 5980 | GLenum renderbuffertarget, |
| 5981 | GLuint renderbuffer) |
| 5982 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 5983 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5984 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5985 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFramebufferTarget); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5986 | return false; |
| 5987 | } |
| 5988 | |
| 5989 | if (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0) |
| 5990 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 5991 | context->validationError(GL_INVALID_ENUM, kErrorInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5992 | return false; |
| 5993 | } |
| 5994 | |
| 5995 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 5996 | renderbuffertarget, renderbuffer); |
| 5997 | } |
| 5998 | |
| 5999 | bool ValidateFramebufferTexture2D(Context *context, |
| 6000 | GLenum target, |
| 6001 | GLenum attachment, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6002 | TextureTarget textarget, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6003 | GLuint texture, |
| 6004 | GLint level) |
| 6005 | { |
| 6006 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 6007 | // extension |
| 6008 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 6009 | level != 0) |
| 6010 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6011 | context->validationError(GL_INVALID_VALUE, kErrorInvalidFramebufferTextureLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6012 | return false; |
| 6013 | } |
| 6014 | |
| 6015 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 6016 | { |
| 6017 | return false; |
| 6018 | } |
| 6019 | |
| 6020 | if (texture != 0) |
| 6021 | { |
| 6022 | gl::Texture *tex = context->getTexture(texture); |
| 6023 | ASSERT(tex); |
| 6024 | |
| 6025 | const gl::Caps &caps = context->getCaps(); |
| 6026 | |
| 6027 | switch (textarget) |
| 6028 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6029 | case TextureTarget::_2D: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6030 | { |
| 6031 | if (level > gl::log2(caps.max2DTextureSize)) |
| 6032 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6033 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6034 | return false; |
| 6035 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6036 | if (tex->getType() != TextureType::_2D) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6037 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6038 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6039 | return false; |
| 6040 | } |
| 6041 | } |
| 6042 | break; |
| 6043 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6044 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6045 | { |
| 6046 | if (level != 0) |
| 6047 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6048 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6049 | return false; |
| 6050 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6051 | if (tex->getType() != TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6052 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6053 | context->validationError(GL_INVALID_OPERATION, |
| 6054 | "Textarget must match the texture target type."); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6055 | return false; |
| 6056 | } |
| 6057 | } |
| 6058 | break; |
| 6059 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6060 | case TextureTarget::CubeMapNegativeX: |
| 6061 | case TextureTarget::CubeMapNegativeY: |
| 6062 | case TextureTarget::CubeMapNegativeZ: |
| 6063 | case TextureTarget::CubeMapPositiveX: |
| 6064 | case TextureTarget::CubeMapPositiveY: |
| 6065 | case TextureTarget::CubeMapPositiveZ: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6066 | { |
| 6067 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
| 6068 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6069 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6070 | return false; |
| 6071 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6072 | if (tex->getType() != TextureType::CubeMap) |
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, |
| 6075 | "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6076 | return false; |
| 6077 | } |
| 6078 | } |
| 6079 | break; |
| 6080 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6081 | case TextureTarget::_2DMultisample: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6082 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6083 | if (context->getClientVersion() < ES_3_1 && |
| 6084 | !context->getExtensions().textureMultisample) |
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 | kErrorMultisampleTextureExtensionOrES31Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6088 | return false; |
| 6089 | } |
| 6090 | |
| 6091 | if (level != 0) |
| 6092 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6093 | context->validationError(GL_INVALID_VALUE, kErrorLevelNotZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6094 | return false; |
| 6095 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 6096 | if (tex->getType() != TextureType::_2DMultisample) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6097 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6098 | context->validationError(GL_INVALID_OPERATION, |
| 6099 | "Textarget must match the texture target type."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6100 | return false; |
| 6101 | } |
| 6102 | } |
| 6103 | break; |
| 6104 | |
| 6105 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6106 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6107 | return false; |
| 6108 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | return true; |
| 6112 | } |
| 6113 | |
| 6114 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 6115 | { |
| 6116 | return ValidateGenOrDelete(context, n); |
| 6117 | } |
| 6118 | |
| 6119 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 6120 | { |
| 6121 | return ValidateGenOrDelete(context, n); |
| 6122 | } |
| 6123 | |
| 6124 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 6125 | { |
| 6126 | return ValidateGenOrDelete(context, n); |
| 6127 | } |
| 6128 | |
| 6129 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 6130 | { |
| 6131 | return ValidateGenOrDelete(context, n); |
| 6132 | } |
| 6133 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6134 | bool ValidateGenerateMipmap(Context *context, TextureType target) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6135 | { |
| 6136 | if (!ValidTextureTarget(context, target)) |
| 6137 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6138 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6139 | return false; |
| 6140 | } |
| 6141 | |
| 6142 | Texture *texture = context->getTargetTexture(target); |
| 6143 | |
| 6144 | if (texture == nullptr) |
| 6145 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6146 | context->validationError(GL_INVALID_OPERATION, kErrorTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6147 | return false; |
| 6148 | } |
| 6149 | |
| 6150 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 6151 | |
| 6152 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 6153 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 6154 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 6155 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6156 | context->validationError(GL_INVALID_OPERATION, kErrorBaseLevelOutOfRange); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6157 | return false; |
| 6158 | } |
| 6159 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6160 | TextureTarget baseTarget = (target == TextureType::CubeMap) |
| 6161 | ? TextureTarget::CubeMapPositiveX |
| 6162 | : NonCubeTextureTypeToTarget(target); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6163 | const auto &format = *(texture->getFormat(baseTarget, effectiveBaseLevel).info); |
| 6164 | if (format.sizedInternalFormat == GL_NONE || format.compressed || format.depthBits > 0 || |
| 6165 | format.stencilBits > 0) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6166 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6167 | context->validationError(GL_INVALID_OPERATION, kErrorGenerateMipmapNotAllowed); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6168 | return false; |
| 6169 | } |
| 6170 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6171 | // GenerateMipmap accepts formats that are unsized or both color renderable and filterable. |
| 6172 | bool formatUnsized = !format.sized; |
| 6173 | bool formatColorRenderableAndFilterable = |
| 6174 | format.filterSupport(context->getClientVersion(), context->getExtensions()) && |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6175 | format.textureAttachmentSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6176 | if (!formatUnsized && !formatColorRenderableAndFilterable) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6177 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6178 | context->validationError(GL_INVALID_OPERATION, kErrorGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6179 | return false; |
| 6180 | } |
| 6181 | |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6182 | // GL_EXT_sRGB adds an unsized SRGB (no alpha) format which has explicitly disabled mipmap |
| 6183 | // generation |
| 6184 | if (format.colorEncoding == GL_SRGB && format.format == GL_RGB) |
| 6185 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6186 | context->validationError(GL_INVALID_OPERATION, kErrorGenerateMipmapNotAllowed); |
Geoff Lang | 536eca1 | 2017-09-13 11:23:35 -0400 | [diff] [blame] | 6187 | return false; |
| 6188 | } |
| 6189 | |
Jiang | e2c0084 | 2018-07-13 16:50:49 +0800 | [diff] [blame] | 6190 | // According to the OpenGL extension spec EXT_sRGB.txt, EXT_SRGB is based on ES 2.0 and |
| 6191 | // generateMipmap is not allowed if texture format is SRGB_EXT or SRGB_ALPHA_EXT. |
| 6192 | if (context->getClientVersion() < Version(3, 0) && format.colorEncoding == GL_SRGB) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6193 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6194 | context->validationError(GL_INVALID_OPERATION, kErrorGenerateMipmapNotAllowed); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6195 | return false; |
| 6196 | } |
| 6197 | |
| 6198 | // Non-power of 2 ES2 check |
| 6199 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
| 6200 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 6201 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 6202 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6203 | ASSERT(target == TextureType::_2D || target == TextureType::Rectangle || |
| 6204 | target == TextureType::CubeMap); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6205 | context->validationError(GL_INVALID_OPERATION, kErrorTextureNotPow2); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6206 | return false; |
| 6207 | } |
| 6208 | |
| 6209 | // Cube completeness check |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6210 | if (target == TextureType::CubeMap && !texture->getTextureState().isCubeComplete()) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6211 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6212 | context->validationError(GL_INVALID_OPERATION, kErrorCubemapIncomplete); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6213 | return false; |
| 6214 | } |
| 6215 | |
| 6216 | return true; |
| 6217 | } |
| 6218 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6219 | bool ValidateGetBufferParameteriv(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 6220 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6221 | GLenum pname, |
| 6222 | GLint *params) |
| 6223 | { |
| 6224 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 6225 | } |
| 6226 | |
| 6227 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 6228 | GLenum target, |
| 6229 | GLenum pname, |
| 6230 | GLint *params) |
| 6231 | { |
| 6232 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 6233 | } |
| 6234 | |
| 6235 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 6236 | { |
| 6237 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 6238 | } |
| 6239 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6240 | bool ValidateGetTexParameterfv(Context *context, TextureType target, GLenum pname, GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6241 | { |
| 6242 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6243 | } |
| 6244 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6245 | bool ValidateGetTexParameteriv(Context *context, TextureType target, GLenum pname, GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6246 | { |
| 6247 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6248 | } |
| 6249 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6250 | bool ValidateGetTexParameterIivOES(Context *context, |
| 6251 | TextureType target, |
| 6252 | GLenum pname, |
| 6253 | GLint *params) |
| 6254 | { |
| 6255 | if (context->getClientMajorVersion() < 3) |
| 6256 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6257 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6258 | return false; |
| 6259 | } |
| 6260 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6261 | } |
| 6262 | |
| 6263 | bool ValidateGetTexParameterIuivOES(Context *context, |
| 6264 | TextureType target, |
| 6265 | GLenum pname, |
| 6266 | GLuint *params) |
| 6267 | { |
| 6268 | if (context->getClientMajorVersion() < 3) |
| 6269 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6270 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6271 | return false; |
| 6272 | } |
| 6273 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 6274 | } |
| 6275 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6276 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
| 6277 | { |
| 6278 | return ValidateGetUniformBase(context, program, location); |
| 6279 | } |
| 6280 | |
| 6281 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
| 6282 | { |
| 6283 | return ValidateGetUniformBase(context, program, location); |
| 6284 | } |
| 6285 | |
| 6286 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 6287 | { |
| 6288 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6289 | } |
| 6290 | |
| 6291 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 6292 | { |
| 6293 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 6294 | } |
| 6295 | |
| 6296 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 6297 | { |
| 6298 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 6299 | } |
| 6300 | |
| 6301 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 6302 | { |
| 6303 | if (!ValidCap(context, cap, true)) |
| 6304 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6305 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6306 | return false; |
| 6307 | } |
| 6308 | |
| 6309 | return true; |
| 6310 | } |
| 6311 | |
| 6312 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 6313 | { |
| 6314 | if (context->hasActiveTransformFeedback(program)) |
| 6315 | { |
| 6316 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6317 | context->validationError(GL_INVALID_OPERATION, |
| 6318 | "Cannot link program while program is " |
| 6319 | "associated with an active transform " |
| 6320 | "feedback object."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6321 | return false; |
| 6322 | } |
| 6323 | |
| 6324 | Program *programObject = GetValidProgram(context, program); |
| 6325 | if (!programObject) |
| 6326 | { |
| 6327 | return false; |
| 6328 | } |
| 6329 | |
| 6330 | return true; |
| 6331 | } |
| 6332 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 6333 | bool ValidateReadPixels(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6334 | GLint x, |
| 6335 | GLint y, |
| 6336 | GLsizei width, |
| 6337 | GLsizei height, |
| 6338 | GLenum format, |
| 6339 | GLenum type, |
| 6340 | void *pixels) |
| 6341 | { |
| 6342 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, nullptr, |
| 6343 | nullptr, pixels); |
| 6344 | } |
| 6345 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6346 | bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6347 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6348 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6349 | } |
| 6350 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6351 | bool ValidateTexParameterfv(Context *context, |
| 6352 | TextureType target, |
| 6353 | GLenum pname, |
| 6354 | const GLfloat *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6355 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6356 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6357 | } |
| 6358 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6359 | bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6360 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6361 | return ValidateTexParameterBase(context, target, pname, -1, false, ¶m); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6362 | } |
| 6363 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6364 | bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6365 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6366 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6367 | } |
| 6368 | |
| 6369 | bool ValidateTexParameterIivOES(Context *context, |
| 6370 | TextureType target, |
| 6371 | GLenum pname, |
| 6372 | const GLint *params) |
| 6373 | { |
| 6374 | if (context->getClientMajorVersion() < 3) |
| 6375 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6376 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6377 | return false; |
| 6378 | } |
| 6379 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
| 6380 | } |
| 6381 | |
| 6382 | bool ValidateTexParameterIuivOES(Context *context, |
| 6383 | TextureType target, |
| 6384 | GLenum pname, |
| 6385 | const GLuint *params) |
| 6386 | { |
| 6387 | if (context->getClientMajorVersion() < 3) |
| 6388 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6389 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6390 | return false; |
| 6391 | } |
| 6392 | return ValidateTexParameterBase(context, target, pname, -1, true, params); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | bool ValidateUseProgram(Context *context, GLuint program) |
| 6396 | { |
| 6397 | if (program != 0) |
| 6398 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 6399 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6400 | if (!programObject) |
| 6401 | { |
| 6402 | // ES 3.1.0 section 7.3 page 72 |
| 6403 | if (context->getShader(program)) |
| 6404 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6405 | context->validationError(GL_INVALID_OPERATION, kErrorExpectedProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6406 | return false; |
| 6407 | } |
| 6408 | else |
| 6409 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6410 | context->validationError(GL_INVALID_VALUE, kErrorInvalidProgramName); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6411 | return false; |
| 6412 | } |
| 6413 | } |
| 6414 | if (!programObject->isLinked()) |
| 6415 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6416 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6417 | return false; |
| 6418 | } |
| 6419 | } |
| 6420 | if (context->getGLState().isTransformFeedbackActiveUnpaused()) |
| 6421 | { |
| 6422 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6423 | context->validationError( |
| 6424 | GL_INVALID_OPERATION, |
| 6425 | "Cannot change active program while transform feedback is unpaused."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6426 | return false; |
| 6427 | } |
| 6428 | |
| 6429 | return true; |
| 6430 | } |
| 6431 | |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6432 | bool ValidateDeleteFencesNV(Context *context, GLsizei n, const GLuint *fences) |
| 6433 | { |
| 6434 | if (!context->getExtensions().fence) |
| 6435 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6436 | context->validationError(GL_INVALID_OPERATION, kErrorNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6437 | return false; |
| 6438 | } |
| 6439 | |
| 6440 | if (n < 0) |
| 6441 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6442 | context->validationError(GL_INVALID_VALUE, kErrorNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6443 | return false; |
| 6444 | } |
| 6445 | |
| 6446 | return true; |
| 6447 | } |
| 6448 | |
| 6449 | bool ValidateFinishFenceNV(Context *context, GLuint fence) |
| 6450 | { |
| 6451 | if (!context->getExtensions().fence) |
| 6452 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6453 | context->validationError(GL_INVALID_OPERATION, kErrorNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6454 | return false; |
| 6455 | } |
| 6456 | |
| 6457 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6458 | |
| 6459 | if (fenceObject == nullptr) |
| 6460 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6461 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6462 | return false; |
| 6463 | } |
| 6464 | |
| 6465 | if (!fenceObject->isSet()) |
| 6466 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6467 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6468 | return false; |
| 6469 | } |
| 6470 | |
| 6471 | return true; |
| 6472 | } |
| 6473 | |
| 6474 | bool ValidateGenFencesNV(Context *context, GLsizei n, GLuint *fences) |
| 6475 | { |
| 6476 | if (!context->getExtensions().fence) |
| 6477 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6478 | context->validationError(GL_INVALID_OPERATION, kErrorNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6479 | return false; |
| 6480 | } |
| 6481 | |
| 6482 | if (n < 0) |
| 6483 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6484 | context->validationError(GL_INVALID_VALUE, kErrorNegativeCount); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6485 | return false; |
| 6486 | } |
| 6487 | |
| 6488 | return true; |
| 6489 | } |
| 6490 | |
| 6491 | bool ValidateGetFenceivNV(Context *context, GLuint fence, GLenum pname, GLint *params) |
| 6492 | { |
| 6493 | if (!context->getExtensions().fence) |
| 6494 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6495 | context->validationError(GL_INVALID_OPERATION, kErrorNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6496 | return false; |
| 6497 | } |
| 6498 | |
| 6499 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6500 | |
| 6501 | if (fenceObject == nullptr) |
| 6502 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6503 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFence); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6504 | return false; |
| 6505 | } |
| 6506 | |
| 6507 | if (!fenceObject->isSet()) |
| 6508 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6509 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFenceState); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6510 | return false; |
| 6511 | } |
| 6512 | |
| 6513 | switch (pname) |
| 6514 | { |
| 6515 | case GL_FENCE_STATUS_NV: |
| 6516 | case GL_FENCE_CONDITION_NV: |
| 6517 | break; |
| 6518 | |
| 6519 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6520 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6521 | return false; |
| 6522 | } |
| 6523 | |
| 6524 | return true; |
| 6525 | } |
| 6526 | |
| 6527 | bool ValidateGetGraphicsResetStatusEXT(Context *context) |
| 6528 | { |
| 6529 | if (!context->getExtensions().robustness) |
| 6530 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6531 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6532 | return false; |
| 6533 | } |
| 6534 | |
| 6535 | return true; |
| 6536 | } |
| 6537 | |
| 6538 | bool ValidateGetTranslatedShaderSourceANGLE(Context *context, |
| 6539 | GLuint shader, |
| 6540 | GLsizei bufsize, |
| 6541 | GLsizei *length, |
| 6542 | GLchar *source) |
| 6543 | { |
| 6544 | if (!context->getExtensions().translatedShaderSource) |
| 6545 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6546 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6547 | return false; |
| 6548 | } |
| 6549 | |
| 6550 | if (bufsize < 0) |
| 6551 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6552 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6553 | return false; |
| 6554 | } |
| 6555 | |
| 6556 | Shader *shaderObject = context->getShader(shader); |
| 6557 | |
| 6558 | if (!shaderObject) |
| 6559 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6560 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidShaderName); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6561 | return false; |
| 6562 | } |
| 6563 | |
| 6564 | return true; |
| 6565 | } |
| 6566 | |
| 6567 | bool ValidateIsFenceNV(Context *context, GLuint fence) |
| 6568 | { |
| 6569 | if (!context->getExtensions().fence) |
| 6570 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6571 | context->validationError(GL_INVALID_OPERATION, kErrorNVFenceNotSupported); |
Jamie Madill | 2b7bbc2 | 2017-12-21 17:30:38 -0500 | [diff] [blame] | 6572 | return false; |
| 6573 | } |
| 6574 | |
| 6575 | return true; |
| 6576 | } |
| 6577 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6578 | bool ValidateSetFenceNV(Context *context, GLuint fence, GLenum condition) |
| 6579 | { |
| 6580 | if (!context->getExtensions().fence) |
| 6581 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6582 | context->validationError(GL_INVALID_OPERATION, kErrorNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6583 | return false; |
| 6584 | } |
| 6585 | |
| 6586 | if (condition != GL_ALL_COMPLETED_NV) |
| 6587 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6588 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFenceCondition); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6589 | return false; |
| 6590 | } |
| 6591 | |
| 6592 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6593 | |
| 6594 | if (fenceObject == nullptr) |
| 6595 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6596 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6597 | return false; |
| 6598 | } |
| 6599 | |
| 6600 | return true; |
| 6601 | } |
| 6602 | |
| 6603 | bool ValidateTestFenceNV(Context *context, GLuint fence) |
| 6604 | { |
| 6605 | if (!context->getExtensions().fence) |
| 6606 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6607 | context->validationError(GL_INVALID_OPERATION, kErrorNVFenceNotSupported); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6608 | return false; |
| 6609 | } |
| 6610 | |
| 6611 | FenceNV *fenceObject = context->getFenceNV(fence); |
| 6612 | |
| 6613 | if (fenceObject == nullptr) |
| 6614 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6615 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFence); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6616 | return false; |
| 6617 | } |
| 6618 | |
| 6619 | if (fenceObject->isSet() != GL_TRUE) |
| 6620 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6621 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFenceState); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6622 | return false; |
| 6623 | } |
| 6624 | |
| 6625 | return true; |
| 6626 | } |
| 6627 | |
| 6628 | bool ValidateTexStorage2DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6629 | TextureType type, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6630 | GLsizei levels, |
| 6631 | GLenum internalformat, |
| 6632 | GLsizei width, |
| 6633 | GLsizei height) |
| 6634 | { |
| 6635 | if (!context->getExtensions().textureStorage) |
| 6636 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6637 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6638 | return false; |
| 6639 | } |
| 6640 | |
| 6641 | if (context->getClientMajorVersion() < 3) |
| 6642 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6643 | return ValidateES2TexStorageParameters(context, type, levels, internalformat, width, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6644 | height); |
| 6645 | } |
| 6646 | |
| 6647 | ASSERT(context->getClientMajorVersion() >= 3); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6648 | return ValidateES3TexStorage2DParameters(context, type, levels, internalformat, width, height, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6649 | 1); |
| 6650 | } |
| 6651 | |
| 6652 | bool ValidateVertexAttribDivisorANGLE(Context *context, GLuint index, GLuint divisor) |
| 6653 | { |
| 6654 | if (!context->getExtensions().instancedArrays) |
| 6655 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6656 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6657 | return false; |
| 6658 | } |
| 6659 | |
| 6660 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6661 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6662 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxVertexAttribute); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6663 | return false; |
| 6664 | } |
| 6665 | |
| 6666 | if (context->getLimitations().attributeZeroRequiresZeroDivisorInEXT) |
| 6667 | { |
| 6668 | if (index == 0 && divisor != 0) |
| 6669 | { |
| 6670 | const char *errorMessage = |
| 6671 | "The current context doesn't support setting a non-zero divisor on the " |
| 6672 | "attribute with index zero. " |
| 6673 | "Please reorder the attributes in your vertex shader so that attribute zero " |
| 6674 | "can have a zero divisor."; |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6675 | context->validationError(GL_INVALID_OPERATION, errorMessage); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6676 | |
| 6677 | // We also output an error message to the debugger window if tracing is active, so |
| 6678 | // that developers can see the error message. |
| 6679 | ERR() << errorMessage; |
| 6680 | return false; |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | return true; |
| 6685 | } |
| 6686 | |
| 6687 | bool ValidateTexImage3DOES(Context *context, |
| 6688 | GLenum target, |
| 6689 | GLint level, |
| 6690 | GLenum internalformat, |
| 6691 | GLsizei width, |
| 6692 | GLsizei height, |
| 6693 | GLsizei depth, |
| 6694 | GLint border, |
| 6695 | GLenum format, |
| 6696 | GLenum type, |
| 6697 | const void *pixels) |
| 6698 | { |
| 6699 | UNIMPLEMENTED(); // FIXME |
| 6700 | return false; |
| 6701 | } |
| 6702 | |
| 6703 | bool ValidatePopGroupMarkerEXT(Context *context) |
| 6704 | { |
| 6705 | if (!context->getExtensions().debugMarker) |
| 6706 | { |
| 6707 | // The debug marker calls should not set error state |
| 6708 | // However, it seems reasonable to set an error state if the extension is not enabled |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6709 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 6710 | return false; |
| 6711 | } |
| 6712 | |
| 6713 | return true; |
| 6714 | } |
| 6715 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6716 | bool ValidateTexStorage1DEXT(Context *context, |
| 6717 | GLenum target, |
| 6718 | GLsizei levels, |
| 6719 | GLenum internalformat, |
| 6720 | GLsizei width) |
| 6721 | { |
| 6722 | UNIMPLEMENTED(); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6723 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6724 | return false; |
| 6725 | } |
| 6726 | |
| 6727 | bool ValidateTexStorage3DEXT(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6728 | TextureType target, |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6729 | GLsizei levels, |
| 6730 | GLenum internalformat, |
| 6731 | GLsizei width, |
| 6732 | GLsizei height, |
| 6733 | GLsizei depth) |
| 6734 | { |
| 6735 | if (!context->getExtensions().textureStorage) |
| 6736 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6737 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6738 | return false; |
| 6739 | } |
| 6740 | |
| 6741 | if (context->getClientMajorVersion() < 3) |
| 6742 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6743 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 6744 | return false; |
| 6745 | } |
| 6746 | |
| 6747 | return ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 6748 | depth); |
| 6749 | } |
| 6750 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6751 | bool ValidateMaxShaderCompilerThreadsKHR(Context *context, GLuint count) |
| 6752 | { |
| 6753 | if (!context->getExtensions().parallelShaderCompile) |
| 6754 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6755 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 6756 | return false; |
| 6757 | } |
| 6758 | return true; |
| 6759 | } |
| 6760 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6761 | bool ValidateMultiDrawArraysANGLE(Context *context, |
| 6762 | PrimitiveMode mode, |
| 6763 | const GLint *firsts, |
| 6764 | const GLsizei *counts, |
| 6765 | GLsizei drawcount) |
| 6766 | { |
| 6767 | if (!context->getExtensions().multiDraw) |
| 6768 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6769 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6770 | return false; |
| 6771 | } |
| 6772 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6773 | { |
| 6774 | if (!ValidateDrawArrays(context, mode, firsts[drawID], counts[drawID])) |
| 6775 | { |
| 6776 | return false; |
| 6777 | } |
| 6778 | } |
| 6779 | return true; |
| 6780 | } |
| 6781 | |
| 6782 | bool ValidateMultiDrawElementsANGLE(Context *context, |
| 6783 | PrimitiveMode mode, |
| 6784 | const GLsizei *counts, |
| 6785 | GLenum type, |
| 6786 | const GLsizei *offsets, |
| 6787 | GLsizei drawcount) |
| 6788 | { |
| 6789 | if (!context->getExtensions().multiDraw) |
| 6790 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame^] | 6791 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame] | 6792 | return false; |
| 6793 | } |
| 6794 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 6795 | { |
| 6796 | const void *indices = reinterpret_cast<void *>(static_cast<long>(offsets[drawID])); |
| 6797 | if (!ValidateDrawElements(context, mode, counts[drawID], type, indices)) |
| 6798 | { |
| 6799 | return false; |
| 6800 | } |
| 6801 | } |
| 6802 | return true; |
| 6803 | } |
| 6804 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6805 | } // namespace gl |