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 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES2.h" |
| 10 | #include "libANGLE/validationES.h" |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 11 | #include "libANGLE/validationES3.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 12 | #include "libANGLE/Context.h" |
| 13 | #include "libANGLE/Texture.h" |
| 14 | #include "libANGLE/Framebuffer.h" |
| 15 | #include "libANGLE/Renderbuffer.h" |
| 16 | #include "libANGLE/formatutils.h" |
| 17 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 18 | #include "libANGLE/Uniform.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 19 | |
| 20 | #include "common/mathutil.h" |
| 21 | #include "common/utilities.h" |
| 22 | |
| 23 | namespace gl |
| 24 | { |
| 25 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 26 | namespace |
| 27 | { |
| 28 | |
| 29 | bool IsPartialBlit(gl::Context *context, |
| 30 | const FramebufferAttachment *readBuffer, |
| 31 | const FramebufferAttachment *writeBuffer, |
| 32 | GLint srcX0, |
| 33 | GLint srcY0, |
| 34 | GLint srcX1, |
| 35 | GLint srcY1, |
| 36 | GLint dstX0, |
| 37 | GLint dstY0, |
| 38 | GLint dstX1, |
| 39 | GLint dstY1) |
| 40 | { |
| 41 | const Extents &writeSize = writeBuffer->getSize(); |
| 42 | const Extents &readSize = readBuffer->getSize(); |
| 43 | |
| 44 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || dstX1 != writeSize.width || |
| 45 | dstY1 != writeSize.height || srcX1 != readSize.width || srcY1 != readSize.height) |
| 46 | { |
| 47 | return true; |
| 48 | } |
| 49 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 50 | if (context->getGLState().isScissorTestEnabled()) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 51 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 52 | const Rectangle &scissor = context->getGLState().getScissor(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 53 | return scissor.x > 0 || scissor.y > 0 || scissor.width < writeSize.width || |
| 54 | scissor.height < writeSize.height; |
| 55 | } |
| 56 | |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | } // anonymous namespace |
| 61 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 62 | bool ValidateES2TexImageParameters(Context *context, GLenum target, GLint level, GLenum internalformat, bool isCompressed, bool isSubImage, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 63 | GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, |
| 64 | GLint border, GLenum format, GLenum type, const GLvoid *pixels) |
| 65 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 66 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 67 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 68 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 69 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 70 | } |
| 71 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 72 | if (!ValidImageSizeParameters(context, target, level, width, height, 1, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 73 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 74 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 75 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 76 | } |
| 77 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 78 | if (level < 0 || xoffset < 0 || |
| 79 | std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 80 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 81 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 82 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 83 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 86 | if (!isSubImage && !isCompressed && internalformat != format) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 87 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 88 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 89 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 92 | const gl::Caps &caps = context->getCaps(); |
| 93 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 94 | if (target == GL_TEXTURE_2D) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 95 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 96 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 97 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 98 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 99 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 100 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 101 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 102 | } |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 103 | else if (IsCubeMapTextureTarget(target)) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 104 | { |
| 105 | if (!isSubImage && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 106 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 107 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 108 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 109 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 110 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 111 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level) || |
| 112 | static_cast<GLuint>(height) > (caps.maxCubeMapTextureSize >> level)) |
| 113 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 114 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 115 | return false; |
| 116 | } |
| 117 | } |
| 118 | else |
| 119 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 120 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 121 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 122 | } |
| 123 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 124 | gl::Texture *texture = context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 125 | if (!texture) |
| 126 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 127 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 128 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 129 | } |
| 130 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 131 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 132 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 133 | if (format != GL_NONE) |
| 134 | { |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 135 | if (gl::GetSizedInternalFormat(format, type) != texture->getInternalFormat(target, level)) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 136 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 137 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 143 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level)) |
| 144 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 145 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 146 | return false; |
| 147 | } |
| 148 | } |
| 149 | else |
| 150 | { |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 151 | if (texture->getImmutableFormat()) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 152 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 153 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 154 | return false; |
| 155 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | // Verify zero border |
| 159 | if (border != 0) |
| 160 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 161 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 162 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 163 | } |
| 164 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 165 | if (isCompressed) |
| 166 | { |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 167 | GLenum actualInternalFormat = |
| 168 | isSubImage ? texture->getInternalFormat(target, level) : internalformat; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 169 | switch (actualInternalFormat) |
| 170 | { |
| 171 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 172 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 173 | if (!context->getExtensions().textureCompressionDXT1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 174 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 175 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 176 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 177 | } |
| 178 | break; |
| 179 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 180 | if (!context->getExtensions().textureCompressionDXT1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 181 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 182 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 183 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 184 | } |
| 185 | break; |
| 186 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 187 | if (!context->getExtensions().textureCompressionDXT5) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 188 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 189 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 190 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 191 | } |
| 192 | break; |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 193 | case GL_ETC1_RGB8_OES: |
| 194 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 195 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 196 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 197 | return false; |
| 198 | } |
| 199 | break; |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 200 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 201 | if (!context->getExtensions().lossyETCDecode) |
| 202 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 203 | context->handleError( |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 204 | Error(GL_INVALID_ENUM, "ANGLE_lossy_etc_decode extension is not supported")); |
| 205 | return false; |
| 206 | } |
| 207 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 208 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 209 | context->handleError(Error( |
tmartino | 0ccd5ae | 2015-10-01 14:33:14 -0400 | [diff] [blame] | 210 | GL_INVALID_ENUM, "internalformat is not a supported compressed internal format")); |
| 211 | return false; |
| 212 | } |
| 213 | if (!ValidCompressedImageSize(context, actualInternalFormat, width, height)) |
| 214 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 215 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 216 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | // validate <type> by itself (used as secondary key below) |
| 222 | switch (type) |
| 223 | { |
| 224 | case GL_UNSIGNED_BYTE: |
| 225 | case GL_UNSIGNED_SHORT_5_6_5: |
| 226 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 227 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 228 | case GL_UNSIGNED_SHORT: |
| 229 | case GL_UNSIGNED_INT: |
| 230 | case GL_UNSIGNED_INT_24_8_OES: |
| 231 | case GL_HALF_FLOAT_OES: |
| 232 | case GL_FLOAT: |
| 233 | break; |
| 234 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 235 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 236 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | // validate <format> + <type> combinations |
| 240 | // - invalid <format> -> sets INVALID_ENUM |
| 241 | // - invalid <format>+<type> combination -> sets INVALID_OPERATION |
| 242 | switch (format) |
| 243 | { |
| 244 | case GL_ALPHA: |
| 245 | case GL_LUMINANCE: |
| 246 | case GL_LUMINANCE_ALPHA: |
| 247 | switch (type) |
| 248 | { |
| 249 | case GL_UNSIGNED_BYTE: |
| 250 | case GL_FLOAT: |
| 251 | case GL_HALF_FLOAT_OES: |
| 252 | break; |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 253 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 254 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 255 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 256 | } |
| 257 | break; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 258 | case GL_RED: |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 259 | case GL_RG: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 260 | if (!context->getExtensions().textureRG) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 261 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 262 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 263 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 264 | } |
| 265 | switch (type) |
| 266 | { |
| 267 | case GL_UNSIGNED_BYTE: |
| 268 | case GL_FLOAT: |
| 269 | case GL_HALF_FLOAT_OES: |
| 270 | break; |
| 271 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 272 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 273 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 274 | } |
| 275 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 276 | case GL_RGB: |
| 277 | switch (type) |
| 278 | { |
| 279 | case GL_UNSIGNED_BYTE: |
| 280 | case GL_UNSIGNED_SHORT_5_6_5: |
| 281 | case GL_FLOAT: |
| 282 | case GL_HALF_FLOAT_OES: |
| 283 | break; |
| 284 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 285 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 286 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 287 | } |
| 288 | break; |
| 289 | case GL_RGBA: |
| 290 | switch (type) |
| 291 | { |
| 292 | case GL_UNSIGNED_BYTE: |
| 293 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 294 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 295 | case GL_FLOAT: |
| 296 | case GL_HALF_FLOAT_OES: |
| 297 | break; |
| 298 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 299 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 300 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 301 | } |
| 302 | break; |
| 303 | case GL_BGRA_EXT: |
| 304 | switch (type) |
| 305 | { |
| 306 | case GL_UNSIGNED_BYTE: |
| 307 | break; |
| 308 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 309 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 310 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 311 | } |
| 312 | break; |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame] | 313 | case GL_SRGB_EXT: |
| 314 | case GL_SRGB_ALPHA_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 315 | if (!context->getExtensions().sRGB) |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame] | 316 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 317 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 318 | return false; |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame] | 319 | } |
| 320 | switch (type) |
| 321 | { |
| 322 | case GL_UNSIGNED_BYTE: |
| 323 | break; |
| 324 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 325 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 326 | return false; |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame] | 327 | } |
| 328 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 329 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below |
| 330 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 331 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 332 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 333 | break; |
| 334 | case GL_DEPTH_COMPONENT: |
| 335 | switch (type) |
| 336 | { |
| 337 | case GL_UNSIGNED_SHORT: |
| 338 | case GL_UNSIGNED_INT: |
| 339 | break; |
| 340 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 341 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 342 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 343 | } |
| 344 | break; |
| 345 | case GL_DEPTH_STENCIL_OES: |
| 346 | switch (type) |
| 347 | { |
| 348 | case GL_UNSIGNED_INT_24_8_OES: |
| 349 | break; |
| 350 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 351 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 352 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 353 | } |
| 354 | break; |
| 355 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 356 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 357 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | switch (format) |
| 361 | { |
| 362 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 363 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 364 | if (context->getExtensions().textureCompressionDXT1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 365 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 366 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 367 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 368 | } |
| 369 | else |
| 370 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 371 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 372 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 373 | } |
| 374 | break; |
| 375 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 376 | if (context->getExtensions().textureCompressionDXT3) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 377 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 378 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 379 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 380 | } |
| 381 | else |
| 382 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 383 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 384 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 385 | } |
| 386 | break; |
| 387 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 388 | if (context->getExtensions().textureCompressionDXT5) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 389 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 390 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 391 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 392 | } |
| 393 | else |
| 394 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 395 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 396 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 397 | } |
| 398 | break; |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 399 | case GL_ETC1_RGB8_OES: |
| 400 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 401 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 402 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 403 | return false; |
| 404 | } |
| 405 | else |
| 406 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 407 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | break; |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 411 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 412 | if (context->getExtensions().lossyETCDecode) |
| 413 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 414 | context->handleError( |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 415 | Error(GL_INVALID_OPERATION, |
| 416 | "ETC1_RGB8_LOSSY_DECODE_ANGLE can't work with this type.")); |
| 417 | return false; |
| 418 | } |
| 419 | else |
| 420 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 421 | context->handleError( |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 422 | Error(GL_INVALID_ENUM, "ANGLE_lossy_etc_decode extension is not supported.")); |
| 423 | return false; |
| 424 | } |
| 425 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 426 | case GL_DEPTH_COMPONENT: |
| 427 | case GL_DEPTH_STENCIL_OES: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 428 | if (!context->getExtensions().depthTextures) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 429 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 430 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 431 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 432 | } |
| 433 | if (target != GL_TEXTURE_2D) |
| 434 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 435 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 436 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 437 | } |
| 438 | // OES_depth_texture supports loading depth data and multiple levels, |
| 439 | // but ANGLE_depth_texture does not |
| 440 | if (pixels != NULL || level != 0) |
| 441 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 442 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 443 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 444 | } |
| 445 | break; |
| 446 | default: |
| 447 | break; |
| 448 | } |
| 449 | |
| 450 | if (type == GL_FLOAT) |
| 451 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 452 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 453 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 454 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 455 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | else if (type == GL_HALF_FLOAT_OES) |
| 459 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 460 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 461 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 462 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 463 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | return true; |
| 469 | } |
| 470 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 471 | bool ValidateES2CopyTexImageParameters(ValidationContext *context, |
| 472 | GLenum target, |
| 473 | GLint level, |
| 474 | GLenum internalformat, |
| 475 | bool isSubImage, |
| 476 | GLint xoffset, |
| 477 | GLint yoffset, |
| 478 | GLint x, |
| 479 | GLint y, |
| 480 | GLsizei width, |
| 481 | GLsizei height, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 482 | GLint border) |
| 483 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 484 | GLenum textureInternalFormat = GL_NONE; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 485 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 486 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 487 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 488 | context->handleError(Error(GL_INVALID_ENUM, "Invalid texture target")); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 489 | return false; |
| 490 | } |
| 491 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 492 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 493 | xoffset, yoffset, 0, x, y, width, height, border, &textureInternalFormat)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 494 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 495 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 496 | } |
| 497 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 498 | const gl::Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 499 | GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat(); |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 500 | const auto &internalFormatInfo = gl::GetInternalFormatInfo(textureInternalFormat); |
| 501 | GLenum textureFormat = internalFormatInfo.format; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 502 | |
| 503 | // [OpenGL ES 2.0.24] table 3.9 |
| 504 | if (isSubImage) |
| 505 | { |
| 506 | switch (textureFormat) |
| 507 | { |
| 508 | case GL_ALPHA: |
| 509 | if (colorbufferFormat != GL_ALPHA8_EXT && |
| 510 | colorbufferFormat != GL_RGBA4 && |
| 511 | colorbufferFormat != GL_RGB5_A1 && |
| 512 | colorbufferFormat != GL_RGBA8_OES) |
| 513 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 514 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 515 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 516 | } |
| 517 | break; |
| 518 | case GL_LUMINANCE: |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 519 | if (colorbufferFormat != GL_R8_EXT && |
| 520 | colorbufferFormat != GL_RG8_EXT && |
| 521 | colorbufferFormat != GL_RGB565 && |
| 522 | colorbufferFormat != GL_RGB8_OES && |
| 523 | colorbufferFormat != GL_RGBA4 && |
| 524 | colorbufferFormat != GL_RGB5_A1 && |
| 525 | colorbufferFormat != GL_RGBA8_OES) |
| 526 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 527 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 528 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 529 | } |
| 530 | break; |
| 531 | case GL_RED_EXT: |
| 532 | if (colorbufferFormat != GL_R8_EXT && |
| 533 | colorbufferFormat != GL_RG8_EXT && |
| 534 | colorbufferFormat != GL_RGB565 && |
| 535 | colorbufferFormat != GL_RGB8_OES && |
| 536 | colorbufferFormat != GL_RGBA4 && |
| 537 | colorbufferFormat != GL_RGB5_A1 && |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 538 | colorbufferFormat != GL_RGBA8_OES && |
| 539 | colorbufferFormat != GL_R32F && |
| 540 | colorbufferFormat != GL_RG32F && |
| 541 | colorbufferFormat != GL_RGB32F && |
| 542 | colorbufferFormat != GL_RGBA32F) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 543 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 544 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 545 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 546 | } |
| 547 | break; |
| 548 | case GL_RG_EXT: |
| 549 | if (colorbufferFormat != GL_RG8_EXT && |
| 550 | colorbufferFormat != GL_RGB565 && |
| 551 | colorbufferFormat != GL_RGB8_OES && |
| 552 | colorbufferFormat != GL_RGBA4 && |
| 553 | colorbufferFormat != GL_RGB5_A1 && |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 554 | colorbufferFormat != GL_RGBA8_OES && |
| 555 | colorbufferFormat != GL_RG32F && |
| 556 | colorbufferFormat != GL_RGB32F && |
| 557 | colorbufferFormat != GL_RGBA32F) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 558 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 559 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 560 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 561 | } |
| 562 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 563 | case GL_RGB: |
| 564 | if (colorbufferFormat != GL_RGB565 && |
| 565 | colorbufferFormat != GL_RGB8_OES && |
| 566 | colorbufferFormat != GL_RGBA4 && |
| 567 | colorbufferFormat != GL_RGB5_A1 && |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 568 | colorbufferFormat != GL_RGBA8_OES && |
| 569 | colorbufferFormat != GL_RGB32F && |
| 570 | colorbufferFormat != GL_RGBA32F) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 571 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 572 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 573 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 574 | } |
| 575 | break; |
| 576 | case GL_LUMINANCE_ALPHA: |
| 577 | case GL_RGBA: |
| 578 | if (colorbufferFormat != GL_RGBA4 && |
| 579 | colorbufferFormat != GL_RGB5_A1 && |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 580 | colorbufferFormat != GL_RGBA8_OES && |
| 581 | colorbufferFormat != GL_RGBA32F) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 582 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 583 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 584 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 585 | } |
| 586 | break; |
| 587 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 588 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 589 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 590 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 591 | case GL_ETC1_RGB8_OES: |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 592 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 593 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 594 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 595 | case GL_DEPTH_COMPONENT: |
| 596 | case GL_DEPTH_STENCIL_OES: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 597 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 598 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 599 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 600 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 601 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 602 | } |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 603 | |
| 604 | if (internalFormatInfo.type == GL_FLOAT && |
| 605 | !context->getExtensions().textureFloat) |
| 606 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 607 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 608 | return false; |
| 609 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 610 | } |
| 611 | else |
| 612 | { |
| 613 | switch (internalformat) |
| 614 | { |
| 615 | case GL_ALPHA: |
| 616 | if (colorbufferFormat != GL_ALPHA8_EXT && |
| 617 | colorbufferFormat != GL_RGBA4 && |
| 618 | colorbufferFormat != GL_RGB5_A1 && |
| 619 | colorbufferFormat != GL_BGRA8_EXT && |
Jamie Madill | 054369e | 2015-01-07 10:57:08 -0500 | [diff] [blame] | 620 | colorbufferFormat != GL_RGBA8_OES && |
| 621 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 622 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 623 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 624 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 625 | } |
| 626 | break; |
| 627 | case GL_LUMINANCE: |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 628 | if (colorbufferFormat != GL_R8_EXT && |
| 629 | colorbufferFormat != GL_RG8_EXT && |
| 630 | colorbufferFormat != GL_RGB565 && |
| 631 | colorbufferFormat != GL_RGB8_OES && |
| 632 | colorbufferFormat != GL_RGBA4 && |
| 633 | colorbufferFormat != GL_RGB5_A1 && |
| 634 | colorbufferFormat != GL_BGRA8_EXT && |
Jamie Madill | 054369e | 2015-01-07 10:57:08 -0500 | [diff] [blame] | 635 | colorbufferFormat != GL_RGBA8_OES && |
| 636 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 637 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 638 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 639 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 640 | } |
| 641 | break; |
| 642 | case GL_RED_EXT: |
| 643 | if (colorbufferFormat != GL_R8_EXT && |
| 644 | colorbufferFormat != GL_RG8_EXT && |
| 645 | colorbufferFormat != GL_RGB565 && |
| 646 | colorbufferFormat != GL_RGB8_OES && |
| 647 | colorbufferFormat != GL_RGBA4 && |
| 648 | colorbufferFormat != GL_RGB5_A1 && |
| 649 | colorbufferFormat != GL_BGRA8_EXT && |
Jamie Madill | 054369e | 2015-01-07 10:57:08 -0500 | [diff] [blame] | 650 | colorbufferFormat != GL_RGBA8_OES && |
| 651 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 652 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 653 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 654 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 655 | } |
| 656 | break; |
| 657 | case GL_RG_EXT: |
| 658 | if (colorbufferFormat != GL_RG8_EXT && |
| 659 | colorbufferFormat != GL_RGB565 && |
| 660 | colorbufferFormat != GL_RGB8_OES && |
| 661 | colorbufferFormat != GL_RGBA4 && |
| 662 | colorbufferFormat != GL_RGB5_A1 && |
| 663 | colorbufferFormat != GL_BGRA8_EXT && |
Jamie Madill | 054369e | 2015-01-07 10:57:08 -0500 | [diff] [blame] | 664 | colorbufferFormat != GL_RGBA8_OES && |
| 665 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 666 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 667 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 668 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 669 | } |
| 670 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 671 | case GL_RGB: |
| 672 | if (colorbufferFormat != GL_RGB565 && |
| 673 | colorbufferFormat != GL_RGB8_OES && |
| 674 | colorbufferFormat != GL_RGBA4 && |
| 675 | colorbufferFormat != GL_RGB5_A1 && |
| 676 | colorbufferFormat != GL_BGRA8_EXT && |
Jamie Madill | 054369e | 2015-01-07 10:57:08 -0500 | [diff] [blame] | 677 | colorbufferFormat != GL_RGBA8_OES && |
| 678 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 679 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 680 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 681 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 682 | } |
| 683 | break; |
| 684 | case GL_LUMINANCE_ALPHA: |
| 685 | case GL_RGBA: |
| 686 | if (colorbufferFormat != GL_RGBA4 && |
| 687 | colorbufferFormat != GL_RGB5_A1 && |
| 688 | colorbufferFormat != GL_BGRA8_EXT && |
Jamie Madill | 054369e | 2015-01-07 10:57:08 -0500 | [diff] [blame] | 689 | colorbufferFormat != GL_RGBA8_OES && |
| 690 | colorbufferFormat != GL_BGR5_A1_ANGLEX) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 691 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 692 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 693 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 694 | } |
| 695 | break; |
| 696 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 697 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 698 | if (context->getExtensions().textureCompressionDXT1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 699 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 700 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 701 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 702 | } |
| 703 | else |
| 704 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 705 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 706 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 707 | } |
| 708 | break; |
| 709 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 710 | if (context->getExtensions().textureCompressionDXT3) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 711 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 712 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 713 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 714 | } |
| 715 | else |
| 716 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 717 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 718 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 719 | } |
| 720 | break; |
| 721 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 722 | if (context->getExtensions().textureCompressionDXT5) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 723 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 724 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 725 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 726 | } |
| 727 | else |
| 728 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 729 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 730 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 731 | } |
| 732 | break; |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 733 | case GL_ETC1_RGB8_OES: |
| 734 | if (context->getExtensions().compressedETC1RGB8Texture) |
| 735 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 736 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 737 | return false; |
| 738 | } |
| 739 | else |
| 740 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 741 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 742 | return false; |
| 743 | } |
| 744 | break; |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 745 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 746 | if (context->getExtensions().lossyETCDecode) |
| 747 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 748 | context->handleError(Error(GL_INVALID_OPERATION, |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 749 | "ETC1_RGB8_LOSSY_DECODE_ANGLE can't be copied to.")); |
| 750 | return false; |
| 751 | } |
| 752 | else |
| 753 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 754 | context->handleError( |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 755 | Error(GL_INVALID_ENUM, "ANGLE_lossy_etc_decode extension is not supported.")); |
| 756 | return false; |
| 757 | } |
| 758 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 759 | case GL_DEPTH_COMPONENT: |
| 760 | case GL_DEPTH_COMPONENT16: |
| 761 | case GL_DEPTH_COMPONENT32_OES: |
| 762 | case GL_DEPTH_STENCIL_OES: |
| 763 | case GL_DEPTH24_STENCIL8_OES: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 764 | if (context->getExtensions().depthTextures) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 765 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 766 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 767 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 768 | } |
| 769 | else |
| 770 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 771 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 772 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 773 | } |
| 774 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 775 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 776 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 780 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 781 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 782 | } |
| 783 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 784 | bool ValidateES2TexStorageParameters(Context *context, GLenum target, GLsizei levels, GLenum internalformat, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 785 | GLsizei width, GLsizei height) |
| 786 | { |
| 787 | if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP) |
| 788 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 789 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 790 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | if (width < 1 || height < 1 || levels < 1) |
| 794 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 795 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 796 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | if (target == GL_TEXTURE_CUBE_MAP && width != height) |
| 800 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 801 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 802 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1) |
| 806 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 807 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 808 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 811 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 812 | if (formatInfo.format == GL_NONE || formatInfo.type == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 813 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 814 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 815 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 816 | } |
| 817 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 818 | const gl::Caps &caps = context->getCaps(); |
| 819 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 820 | switch (target) |
| 821 | { |
| 822 | case GL_TEXTURE_2D: |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 823 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 824 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 825 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 826 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 827 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 828 | } |
| 829 | break; |
| 830 | case GL_TEXTURE_CUBE_MAP: |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 831 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize || |
| 832 | static_cast<GLuint>(height) > caps.maxCubeMapTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 833 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 834 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 835 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 836 | } |
| 837 | break; |
| 838 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 839 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 840 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 841 | } |
| 842 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 843 | if (levels != 1 && !context->getExtensions().textureNPOT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 844 | { |
| 845 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 846 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 847 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 848 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
| 852 | switch (internalformat) |
| 853 | { |
| 854 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 855 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 856 | if (!context->getExtensions().textureCompressionDXT1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 857 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 858 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 859 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 860 | } |
| 861 | break; |
| 862 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 863 | if (!context->getExtensions().textureCompressionDXT3) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 864 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 865 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 866 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 867 | } |
| 868 | break; |
| 869 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 870 | if (!context->getExtensions().textureCompressionDXT5) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 871 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 872 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 873 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 874 | } |
| 875 | break; |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 876 | case GL_ETC1_RGB8_OES: |
| 877 | if (!context->getExtensions().compressedETC1RGB8Texture) |
| 878 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 879 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 880 | return false; |
| 881 | } |
| 882 | break; |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 883 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 884 | if (!context->getExtensions().lossyETCDecode) |
| 885 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 886 | context->handleError( |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 887 | Error(GL_INVALID_ENUM, "ANGLE_lossy_etc_decode extension is not supported.")); |
| 888 | return false; |
| 889 | } |
| 890 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 891 | case GL_RGBA32F_EXT: |
| 892 | case GL_RGB32F_EXT: |
| 893 | case GL_ALPHA32F_EXT: |
| 894 | case GL_LUMINANCE32F_EXT: |
| 895 | case GL_LUMINANCE_ALPHA32F_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 896 | if (!context->getExtensions().textureFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 897 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 898 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 899 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 900 | } |
| 901 | break; |
| 902 | case GL_RGBA16F_EXT: |
| 903 | case GL_RGB16F_EXT: |
| 904 | case GL_ALPHA16F_EXT: |
| 905 | case GL_LUMINANCE16F_EXT: |
| 906 | case GL_LUMINANCE_ALPHA16F_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 907 | if (!context->getExtensions().textureHalfFloat) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 908 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 909 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 910 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 911 | } |
| 912 | break; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 913 | case GL_R8_EXT: |
| 914 | case GL_RG8_EXT: |
| 915 | case GL_R16F_EXT: |
| 916 | case GL_RG16F_EXT: |
| 917 | case GL_R32F_EXT: |
| 918 | case GL_RG32F_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 919 | if (!context->getExtensions().textureRG) |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 920 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 921 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 922 | return false; |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 923 | } |
| 924 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 925 | case GL_DEPTH_COMPONENT16: |
| 926 | case GL_DEPTH_COMPONENT32_OES: |
| 927 | case GL_DEPTH24_STENCIL8_OES: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 928 | if (!context->getExtensions().depthTextures) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 929 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 930 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 931 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 932 | } |
| 933 | if (target != GL_TEXTURE_2D) |
| 934 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 935 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 936 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 937 | } |
| 938 | // ANGLE_depth_texture only supports 1-level textures |
| 939 | if (levels != 1) |
| 940 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 941 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 942 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 943 | } |
| 944 | break; |
| 945 | default: |
| 946 | break; |
| 947 | } |
| 948 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 949 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 950 | if (!texture || texture->id() == 0) |
| 951 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 952 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 953 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 954 | } |
| 955 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 956 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 957 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 958 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 959 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | return true; |
| 963 | } |
| 964 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 965 | // check for combinations of format and type that are valid for ReadPixels |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 966 | bool ValidES2ReadFormatType(ValidationContext *context, GLenum format, GLenum type) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 967 | { |
| 968 | switch (format) |
| 969 | { |
| 970 | case GL_RGBA: |
| 971 | switch (type) |
| 972 | { |
| 973 | case GL_UNSIGNED_BYTE: |
| 974 | break; |
| 975 | default: |
| 976 | return false; |
| 977 | } |
| 978 | break; |
| 979 | case GL_BGRA_EXT: |
| 980 | switch (type) |
| 981 | { |
| 982 | case GL_UNSIGNED_BYTE: |
| 983 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 984 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 985 | break; |
| 986 | default: |
| 987 | return false; |
| 988 | } |
| 989 | break; |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 990 | case GL_RG_EXT: |
| 991 | case GL_RED_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 992 | if (!context->getExtensions().textureRG) |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 993 | { |
| 994 | return false; |
| 995 | } |
| 996 | switch (type) |
| 997 | { |
| 998 | case GL_UNSIGNED_BYTE: |
| 999 | break; |
| 1000 | default: |
| 1001 | return false; |
| 1002 | } |
| 1003 | break; |
| 1004 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1005 | default: |
| 1006 | return false; |
| 1007 | } |
| 1008 | return true; |
| 1009 | } |
| 1010 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1011 | bool ValidateDiscardFramebufferEXT(Context *context, GLenum target, GLsizei numAttachments, |
| 1012 | const GLenum *attachments) |
| 1013 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1014 | if (!context->getExtensions().discardFramebuffer) |
| 1015 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1016 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1017 | return false; |
| 1018 | } |
| 1019 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1020 | bool defaultFramebuffer = false; |
| 1021 | |
| 1022 | switch (target) |
| 1023 | { |
| 1024 | case GL_FRAMEBUFFER: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1025 | defaultFramebuffer = |
| 1026 | (context->getGLState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
| 1027 | break; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1028 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1029 | context->handleError(Error(GL_INVALID_ENUM, "Invalid framebuffer target")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1030 | return false; |
| 1031 | } |
| 1032 | |
| 1033 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, defaultFramebuffer); |
| 1034 | } |
| 1035 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1036 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 1037 | { |
| 1038 | if (!context->getExtensions().vertexArrayObject) |
| 1039 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1040 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1041 | return false; |
| 1042 | } |
| 1043 | |
| 1044 | return ValidateBindVertexArrayBase(context, array); |
| 1045 | } |
| 1046 | |
| 1047 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n) |
| 1048 | { |
| 1049 | if (!context->getExtensions().vertexArrayObject) |
| 1050 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1051 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1052 | return false; |
| 1053 | } |
| 1054 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1055 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n) |
| 1059 | { |
| 1060 | if (!context->getExtensions().vertexArrayObject) |
| 1061 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1062 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1063 | return false; |
| 1064 | } |
| 1065 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1066 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | bool ValidateIsVertexArrayOES(Context *context) |
| 1070 | { |
| 1071 | if (!context->getExtensions().vertexArrayObject) |
| 1072 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1073 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1074 | return false; |
| 1075 | } |
| 1076 | |
| 1077 | return true; |
| 1078 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1079 | |
| 1080 | bool ValidateProgramBinaryOES(Context *context, |
| 1081 | GLuint program, |
| 1082 | GLenum binaryFormat, |
| 1083 | const void *binary, |
| 1084 | GLint length) |
| 1085 | { |
| 1086 | if (!context->getExtensions().getProgramBinary) |
| 1087 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1088 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1089 | return false; |
| 1090 | } |
| 1091 | |
| 1092 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1093 | } |
| 1094 | |
| 1095 | bool ValidateGetProgramBinaryOES(Context *context, |
| 1096 | GLuint program, |
| 1097 | GLsizei bufSize, |
| 1098 | GLsizei *length, |
| 1099 | GLenum *binaryFormat, |
| 1100 | void *binary) |
| 1101 | { |
| 1102 | if (!context->getExtensions().getProgramBinary) |
| 1103 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1104 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1105 | return false; |
| 1106 | } |
| 1107 | |
| 1108 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1109 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1110 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1111 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 1112 | { |
| 1113 | switch (source) |
| 1114 | { |
| 1115 | case GL_DEBUG_SOURCE_API: |
| 1116 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 1117 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 1118 | case GL_DEBUG_SOURCE_OTHER: |
| 1119 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 1120 | return !mustBeThirdPartyOrApplication; |
| 1121 | |
| 1122 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 1123 | case GL_DEBUG_SOURCE_APPLICATION: |
| 1124 | return true; |
| 1125 | |
| 1126 | default: |
| 1127 | return false; |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | static bool ValidDebugType(GLenum type) |
| 1132 | { |
| 1133 | switch (type) |
| 1134 | { |
| 1135 | case GL_DEBUG_TYPE_ERROR: |
| 1136 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 1137 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 1138 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 1139 | case GL_DEBUG_TYPE_PORTABILITY: |
| 1140 | case GL_DEBUG_TYPE_OTHER: |
| 1141 | case GL_DEBUG_TYPE_MARKER: |
| 1142 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 1143 | case GL_DEBUG_TYPE_POP_GROUP: |
| 1144 | return true; |
| 1145 | |
| 1146 | default: |
| 1147 | return false; |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | static bool ValidDebugSeverity(GLenum severity) |
| 1152 | { |
| 1153 | switch (severity) |
| 1154 | { |
| 1155 | case GL_DEBUG_SEVERITY_HIGH: |
| 1156 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 1157 | case GL_DEBUG_SEVERITY_LOW: |
| 1158 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 1159 | return true; |
| 1160 | |
| 1161 | default: |
| 1162 | return false; |
| 1163 | } |
| 1164 | } |
| 1165 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1166 | bool ValidateDebugMessageControlKHR(Context *context, |
| 1167 | GLenum source, |
| 1168 | GLenum type, |
| 1169 | GLenum severity, |
| 1170 | GLsizei count, |
| 1171 | const GLuint *ids, |
| 1172 | GLboolean enabled) |
| 1173 | { |
| 1174 | if (!context->getExtensions().debug) |
| 1175 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1176 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1177 | return false; |
| 1178 | } |
| 1179 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1180 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 1181 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1182 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug source.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1183 | return false; |
| 1184 | } |
| 1185 | |
| 1186 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 1187 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1188 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug type.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1189 | return false; |
| 1190 | } |
| 1191 | |
| 1192 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 1193 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1194 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug severity.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1195 | return false; |
| 1196 | } |
| 1197 | |
| 1198 | if (count > 0) |
| 1199 | { |
| 1200 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 1201 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1202 | context->handleError(Error( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1203 | GL_INVALID_OPERATION, |
| 1204 | "If count is greater than zero, source and severity cannot be GL_DONT_CARE.")); |
| 1205 | return false; |
| 1206 | } |
| 1207 | |
| 1208 | if (severity != GL_DONT_CARE) |
| 1209 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1210 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1211 | Error(GL_INVALID_OPERATION, |
| 1212 | "If count is greater than zero, severity must be GL_DONT_CARE.")); |
| 1213 | return false; |
| 1214 | } |
| 1215 | } |
| 1216 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1217 | return true; |
| 1218 | } |
| 1219 | |
| 1220 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 1221 | GLenum source, |
| 1222 | GLenum type, |
| 1223 | GLuint id, |
| 1224 | GLenum severity, |
| 1225 | GLsizei length, |
| 1226 | const GLchar *buf) |
| 1227 | { |
| 1228 | if (!context->getExtensions().debug) |
| 1229 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1230 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1231 | return false; |
| 1232 | } |
| 1233 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1234 | if (!context->getGLState().getDebug().isOutputEnabled()) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1235 | { |
| 1236 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 1237 | // not generate an error. |
| 1238 | return false; |
| 1239 | } |
| 1240 | |
| 1241 | if (!ValidDebugSeverity(severity)) |
| 1242 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1243 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug severity.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1244 | return false; |
| 1245 | } |
| 1246 | |
| 1247 | if (!ValidDebugType(type)) |
| 1248 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1249 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug type.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1250 | return false; |
| 1251 | } |
| 1252 | |
| 1253 | if (!ValidDebugSource(source, true)) |
| 1254 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1255 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug source.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1256 | return false; |
| 1257 | } |
| 1258 | |
| 1259 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 1260 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 1261 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1262 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1263 | Error(GL_INVALID_VALUE, "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH.")); |
| 1264 | return false; |
| 1265 | } |
| 1266 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1267 | return true; |
| 1268 | } |
| 1269 | |
| 1270 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 1271 | GLDEBUGPROCKHR callback, |
| 1272 | const void *userParam) |
| 1273 | { |
| 1274 | if (!context->getExtensions().debug) |
| 1275 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1276 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1277 | return false; |
| 1278 | } |
| 1279 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1280 | return true; |
| 1281 | } |
| 1282 | |
| 1283 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 1284 | GLuint count, |
| 1285 | GLsizei bufSize, |
| 1286 | GLenum *sources, |
| 1287 | GLenum *types, |
| 1288 | GLuint *ids, |
| 1289 | GLenum *severities, |
| 1290 | GLsizei *lengths, |
| 1291 | GLchar *messageLog) |
| 1292 | { |
| 1293 | if (!context->getExtensions().debug) |
| 1294 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1295 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1296 | return false; |
| 1297 | } |
| 1298 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1299 | if (bufSize < 0 && messageLog != nullptr) |
| 1300 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1301 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1302 | Error(GL_INVALID_VALUE, "bufSize must be positive if messageLog is not null.")); |
| 1303 | return false; |
| 1304 | } |
| 1305 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1306 | return true; |
| 1307 | } |
| 1308 | |
| 1309 | bool ValidatePushDebugGroupKHR(Context *context, |
| 1310 | GLenum source, |
| 1311 | GLuint id, |
| 1312 | GLsizei length, |
| 1313 | const GLchar *message) |
| 1314 | { |
| 1315 | if (!context->getExtensions().debug) |
| 1316 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1317 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1318 | return false; |
| 1319 | } |
| 1320 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1321 | if (!ValidDebugSource(source, true)) |
| 1322 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1323 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug source.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1324 | return false; |
| 1325 | } |
| 1326 | |
| 1327 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 1328 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 1329 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1330 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1331 | Error(GL_INVALID_VALUE, "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH.")); |
| 1332 | return false; |
| 1333 | } |
| 1334 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1335 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1336 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 1337 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1338 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1339 | Error(GL_STACK_OVERFLOW, |
| 1340 | "Cannot push more than GL_MAX_DEBUG_GROUP_STACK_DEPTH debug groups.")); |
| 1341 | return false; |
| 1342 | } |
| 1343 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1344 | return true; |
| 1345 | } |
| 1346 | |
| 1347 | bool ValidatePopDebugGroupKHR(Context *context) |
| 1348 | { |
| 1349 | if (!context->getExtensions().debug) |
| 1350 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1351 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1352 | return false; |
| 1353 | } |
| 1354 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1355 | size_t currentStackSize = context->getGLState().getDebug().getGroupStackDepth(); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1356 | if (currentStackSize <= 1) |
| 1357 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1358 | context->handleError(Error(GL_STACK_UNDERFLOW, "Cannot pop the default debug group.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1359 | return false; |
| 1360 | } |
| 1361 | |
| 1362 | return true; |
| 1363 | } |
| 1364 | |
| 1365 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 1366 | { |
| 1367 | switch (identifier) |
| 1368 | { |
| 1369 | case GL_BUFFER: |
| 1370 | if (context->getBuffer(name) == nullptr) |
| 1371 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1372 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid buffer.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1373 | return false; |
| 1374 | } |
| 1375 | return true; |
| 1376 | |
| 1377 | case GL_SHADER: |
| 1378 | if (context->getShader(name) == nullptr) |
| 1379 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1380 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid shader.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1381 | return false; |
| 1382 | } |
| 1383 | return true; |
| 1384 | |
| 1385 | case GL_PROGRAM: |
| 1386 | if (context->getProgram(name) == nullptr) |
| 1387 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1388 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid program.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1389 | return false; |
| 1390 | } |
| 1391 | return true; |
| 1392 | |
| 1393 | case GL_VERTEX_ARRAY: |
| 1394 | if (context->getVertexArray(name) == nullptr) |
| 1395 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1396 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid vertex array.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1397 | return false; |
| 1398 | } |
| 1399 | return true; |
| 1400 | |
| 1401 | case GL_QUERY: |
| 1402 | if (context->getQuery(name) == nullptr) |
| 1403 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1404 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid query.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1405 | return false; |
| 1406 | } |
| 1407 | return true; |
| 1408 | |
| 1409 | case GL_TRANSFORM_FEEDBACK: |
| 1410 | if (context->getTransformFeedback(name) == nullptr) |
| 1411 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1412 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1413 | Error(GL_INVALID_VALUE, "name is not a valid transform feedback.")); |
| 1414 | return false; |
| 1415 | } |
| 1416 | return true; |
| 1417 | |
| 1418 | case GL_SAMPLER: |
| 1419 | if (context->getSampler(name) == nullptr) |
| 1420 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1421 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid sampler.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1422 | return false; |
| 1423 | } |
| 1424 | return true; |
| 1425 | |
| 1426 | case GL_TEXTURE: |
| 1427 | if (context->getTexture(name) == nullptr) |
| 1428 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1429 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid texture.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1430 | return false; |
| 1431 | } |
| 1432 | return true; |
| 1433 | |
| 1434 | case GL_RENDERBUFFER: |
| 1435 | if (context->getRenderbuffer(name) == nullptr) |
| 1436 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1437 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid renderbuffer.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1438 | return false; |
| 1439 | } |
| 1440 | return true; |
| 1441 | |
| 1442 | case GL_FRAMEBUFFER: |
| 1443 | if (context->getFramebuffer(name) == nullptr) |
| 1444 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1445 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid framebuffer.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1446 | return false; |
| 1447 | } |
| 1448 | return true; |
| 1449 | |
| 1450 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1451 | context->handleError(Error(GL_INVALID_ENUM, "Invalid identifier.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1452 | return false; |
| 1453 | } |
| 1454 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1455 | return true; |
| 1456 | } |
| 1457 | |
| 1458 | bool ValidateObjectLabelKHR(Context *context, |
| 1459 | GLenum identifier, |
| 1460 | GLuint name, |
| 1461 | GLsizei length, |
| 1462 | const GLchar *label) |
| 1463 | { |
| 1464 | if (!context->getExtensions().debug) |
| 1465 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1466 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1467 | return false; |
| 1468 | } |
| 1469 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1470 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 1471 | { |
| 1472 | return false; |
| 1473 | } |
| 1474 | |
| 1475 | size_t labelLength = (length < 0) ? strlen(label) : length; |
| 1476 | if (labelLength > context->getExtensions().maxLabelLength) |
| 1477 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1478 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1479 | Error(GL_INVALID_VALUE, "Label length is larger than GL_MAX_LABEL_LENGTH.")); |
| 1480 | return false; |
| 1481 | } |
| 1482 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1483 | return true; |
| 1484 | } |
| 1485 | |
| 1486 | bool ValidateGetObjectLabelKHR(Context *context, |
| 1487 | GLenum identifier, |
| 1488 | GLuint name, |
| 1489 | GLsizei bufSize, |
| 1490 | GLsizei *length, |
| 1491 | GLchar *label) |
| 1492 | { |
| 1493 | if (!context->getExtensions().debug) |
| 1494 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1495 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1496 | return false; |
| 1497 | } |
| 1498 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1499 | if (bufSize < 0) |
| 1500 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1501 | context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1502 | return false; |
| 1503 | } |
| 1504 | |
| 1505 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 1506 | { |
| 1507 | return false; |
| 1508 | } |
| 1509 | |
| 1510 | // Can no-op if bufSize is zero. |
| 1511 | return bufSize > 0; |
| 1512 | } |
| 1513 | |
| 1514 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 1515 | { |
| 1516 | if (context->getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
| 1517 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1518 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid sync.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1519 | return false; |
| 1520 | } |
| 1521 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1522 | return true; |
| 1523 | } |
| 1524 | |
| 1525 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 1526 | const void *ptr, |
| 1527 | GLsizei length, |
| 1528 | const GLchar *label) |
| 1529 | { |
| 1530 | if (!context->getExtensions().debug) |
| 1531 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1532 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1533 | return false; |
| 1534 | } |
| 1535 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1536 | if (!ValidateObjectPtrName(context, ptr)) |
| 1537 | { |
| 1538 | return false; |
| 1539 | } |
| 1540 | |
| 1541 | size_t labelLength = (length < 0) ? strlen(label) : length; |
| 1542 | if (labelLength > context->getExtensions().maxLabelLength) |
| 1543 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1544 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1545 | Error(GL_INVALID_VALUE, "Label length is larger than GL_MAX_LABEL_LENGTH.")); |
| 1546 | return false; |
| 1547 | } |
| 1548 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1549 | return true; |
| 1550 | } |
| 1551 | |
| 1552 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 1553 | const void *ptr, |
| 1554 | GLsizei bufSize, |
| 1555 | GLsizei *length, |
| 1556 | GLchar *label) |
| 1557 | { |
| 1558 | if (!context->getExtensions().debug) |
| 1559 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1560 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1561 | return false; |
| 1562 | } |
| 1563 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1564 | if (bufSize < 0) |
| 1565 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1566 | context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1567 | return false; |
| 1568 | } |
| 1569 | |
| 1570 | if (!ValidateObjectPtrName(context, ptr)) |
| 1571 | { |
| 1572 | return false; |
| 1573 | } |
| 1574 | |
| 1575 | // Can no-op if bufSize is zero. |
| 1576 | return bufSize > 0; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 1580 | { |
| 1581 | if (!context->getExtensions().debug) |
| 1582 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1583 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1584 | return false; |
| 1585 | } |
| 1586 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1587 | // TODO: represent this in Context::getQueryParameterInfo. |
| 1588 | switch (pname) |
| 1589 | { |
| 1590 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 1591 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 1592 | break; |
| 1593 | |
| 1594 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1595 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1596 | return false; |
| 1597 | } |
| 1598 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1599 | return true; |
| 1600 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1601 | |
| 1602 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 1603 | GLint srcX0, |
| 1604 | GLint srcY0, |
| 1605 | GLint srcX1, |
| 1606 | GLint srcY1, |
| 1607 | GLint dstX0, |
| 1608 | GLint dstY0, |
| 1609 | GLint dstX1, |
| 1610 | GLint dstY1, |
| 1611 | GLbitfield mask, |
| 1612 | GLenum filter) |
| 1613 | { |
| 1614 | if (!context->getExtensions().framebufferBlit) |
| 1615 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1616 | context->handleError(Error(GL_INVALID_OPERATION, "Blit extension not available.")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1617 | return false; |
| 1618 | } |
| 1619 | |
| 1620 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 1621 | { |
| 1622 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1623 | context->handleError(Error( |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1624 | GL_INVALID_OPERATION, |
| 1625 | "Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.")); |
| 1626 | return false; |
| 1627 | } |
| 1628 | |
| 1629 | if (filter == GL_LINEAR) |
| 1630 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1631 | context->handleError(Error(GL_INVALID_ENUM, "Linear blit not supported in this extension")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1632 | return false; |
| 1633 | } |
| 1634 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1635 | const Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 1636 | const Framebuffer *drawFramebuffer = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1637 | |
| 1638 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1639 | { |
| 1640 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 1641 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 1642 | |
| 1643 | if (readColorAttachment && drawColorAttachment) |
| 1644 | { |
| 1645 | if (!(readColorAttachment->type() == GL_TEXTURE && |
| 1646 | readColorAttachment->getTextureImageIndex().type == GL_TEXTURE_2D) && |
| 1647 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 1648 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 1649 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1650 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1651 | return false; |
| 1652 | } |
| 1653 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1654 | for (size_t drawbufferIdx = 0; |
| 1655 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1656 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1657 | const FramebufferAttachment *attachment = |
| 1658 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1659 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1660 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1661 | if (!(attachment->type() == GL_TEXTURE && |
| 1662 | attachment->getTextureImageIndex().type == GL_TEXTURE_2D) && |
| 1663 | attachment->type() != GL_RENDERBUFFER && |
| 1664 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 1665 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1666 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1667 | return false; |
| 1668 | } |
| 1669 | |
| 1670 | // Return an error if the destination formats do not match |
| 1671 | if (attachment->getInternalFormat() != readColorAttachment->getInternalFormat()) |
| 1672 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1673 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1674 | return false; |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1679 | int readSamples = readFramebuffer->getSamples(context->getContextState()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1680 | |
| 1681 | if (readSamples != 0 && |
| 1682 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 1683 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 1684 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1685 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1686 | return false; |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 1692 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1693 | for (size_t i = 0; i < 2; i++) |
| 1694 | { |
| 1695 | if (mask & masks[i]) |
| 1696 | { |
| 1697 | const FramebufferAttachment *readBuffer = |
| 1698 | readFramebuffer->getAttachment(attachments[i]); |
| 1699 | const FramebufferAttachment *drawBuffer = |
| 1700 | drawFramebuffer->getAttachment(attachments[i]); |
| 1701 | |
| 1702 | if (readBuffer && drawBuffer) |
| 1703 | { |
| 1704 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 1705 | dstX0, dstY0, dstX1, dstY1)) |
| 1706 | { |
| 1707 | // only whole-buffer copies are permitted |
| 1708 | ERR( |
| 1709 | "Only whole-buffer depth and stencil blits are supported by this " |
| 1710 | "implementation."); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1711 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1712 | return false; |
| 1713 | } |
| 1714 | |
| 1715 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 1716 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1717 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1718 | return false; |
| 1719 | } |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 1725 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1726 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1727 | |
| 1728 | bool ValidateClear(ValidationContext *context, GLbitfield mask) |
| 1729 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1730 | const Framebuffer *framebufferObject = context->getGLState().getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1731 | ASSERT(framebufferObject); |
| 1732 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1733 | if (framebufferObject->checkStatus(context->getContextState()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1734 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1735 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1736 | return false; |
| 1737 | } |
| 1738 | |
| 1739 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 1740 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1741 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1742 | return false; |
| 1743 | } |
| 1744 | |
| 1745 | return true; |
| 1746 | } |
| 1747 | |
| 1748 | bool ValidateDrawBuffersEXT(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 1749 | { |
| 1750 | if (!context->getExtensions().drawBuffers) |
| 1751 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1752 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not supported.")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1753 | return false; |
| 1754 | } |
| 1755 | |
| 1756 | return ValidateDrawBuffersBase(context, n, bufs); |
| 1757 | } |
| 1758 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1759 | bool ValidateTexImage2D(Context *context, |
| 1760 | GLenum target, |
| 1761 | GLint level, |
| 1762 | GLint internalformat, |
| 1763 | GLsizei width, |
| 1764 | GLsizei height, |
| 1765 | GLint border, |
| 1766 | GLenum format, |
| 1767 | GLenum type, |
| 1768 | const GLvoid *pixels) |
| 1769 | { |
| 1770 | if (context->getClientVersion() < 3) |
| 1771 | { |
| 1772 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 1773 | 0, 0, width, height, border, format, type, pixels); |
| 1774 | } |
| 1775 | |
| 1776 | ASSERT(context->getClientVersion() >= 3); |
| 1777 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 1778 | 0, 0, width, height, 1, border, format, type, pixels); |
| 1779 | } |
| 1780 | |
| 1781 | bool ValidateTexSubImage2D(Context *context, |
| 1782 | GLenum target, |
| 1783 | GLint level, |
| 1784 | GLint xoffset, |
| 1785 | GLint yoffset, |
| 1786 | GLsizei width, |
| 1787 | GLsizei height, |
| 1788 | GLenum format, |
| 1789 | GLenum type, |
| 1790 | const GLvoid *pixels) |
| 1791 | { |
| 1792 | |
| 1793 | if (context->getClientVersion() < 3) |
| 1794 | { |
| 1795 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1796 | yoffset, width, height, 0, format, type, pixels); |
| 1797 | } |
| 1798 | |
| 1799 | ASSERT(context->getClientVersion() >= 3); |
| 1800 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1801 | yoffset, 0, width, height, 1, 0, format, type, pixels); |
| 1802 | } |
| 1803 | |
| 1804 | bool ValidateCompressedTexImage2D(Context *context, |
| 1805 | GLenum target, |
| 1806 | GLint level, |
| 1807 | GLenum internalformat, |
| 1808 | GLsizei width, |
| 1809 | GLsizei height, |
| 1810 | GLint border, |
| 1811 | GLsizei imageSize, |
| 1812 | const GLvoid *data) |
| 1813 | { |
| 1814 | if (context->getClientVersion() < 3) |
| 1815 | { |
| 1816 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
| 1817 | 0, width, height, border, GL_NONE, GL_NONE, data)) |
| 1818 | { |
| 1819 | return false; |
| 1820 | } |
| 1821 | } |
| 1822 | else |
| 1823 | { |
| 1824 | ASSERT(context->getClientVersion() >= 3); |
| 1825 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
| 1826 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, |
| 1827 | data)) |
| 1828 | { |
| 1829 | return false; |
| 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1834 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1835 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, 1)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1836 | if (blockSizeOrErr.isError()) |
| 1837 | { |
| 1838 | context->handleError(blockSizeOrErr.getError()); |
| 1839 | return false; |
| 1840 | } |
| 1841 | |
| 1842 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1843 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1844 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1845 | return false; |
| 1846 | } |
| 1847 | |
| 1848 | return true; |
| 1849 | } |
| 1850 | |
| 1851 | bool ValidateCompressedTexSubImage2D(Context *context, |
| 1852 | GLenum target, |
| 1853 | GLint level, |
| 1854 | GLint xoffset, |
| 1855 | GLint yoffset, |
| 1856 | GLsizei width, |
| 1857 | GLsizei height, |
| 1858 | GLenum format, |
| 1859 | GLsizei imageSize, |
| 1860 | const GLvoid *data) |
| 1861 | { |
| 1862 | if (context->getClientVersion() < 3) |
| 1863 | { |
| 1864 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
| 1865 | yoffset, width, height, 0, GL_NONE, GL_NONE, data)) |
| 1866 | { |
| 1867 | return false; |
| 1868 | } |
| 1869 | } |
| 1870 | else |
| 1871 | { |
| 1872 | ASSERT(context->getClientVersion() >= 3); |
| 1873 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
| 1874 | yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, |
| 1875 | data)) |
| 1876 | { |
| 1877 | return false; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | const InternalFormat &formatInfo = GetInternalFormatInfo(format); |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1882 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1883 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, 1)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1884 | if (blockSizeOrErr.isError()) |
| 1885 | { |
| 1886 | context->handleError(blockSizeOrErr.getError()); |
| 1887 | return false; |
| 1888 | } |
| 1889 | |
| 1890 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1891 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1892 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1893 | return false; |
| 1894 | } |
| 1895 | |
| 1896 | return true; |
| 1897 | } |
| 1898 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1899 | bool ValidateGetBufferPointervOES(Context *context, GLenum target, GLenum pname, void **params) |
| 1900 | { |
| 1901 | if (!context->getExtensions().mapBuffer) |
| 1902 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1903 | context->handleError(Error(GL_INVALID_OPERATION, "Map buffer extension not available.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1904 | return false; |
| 1905 | } |
| 1906 | |
| 1907 | return ValidateGetBufferPointervBase(context, target, pname, params); |
| 1908 | } |
| 1909 | |
| 1910 | bool ValidateMapBufferOES(Context *context, GLenum target, GLenum access) |
| 1911 | { |
| 1912 | if (!context->getExtensions().mapBuffer) |
| 1913 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1914 | context->handleError(Error(GL_INVALID_OPERATION, "Map buffer extension not available.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1915 | return false; |
| 1916 | } |
| 1917 | |
| 1918 | if (!ValidBufferTarget(context, target)) |
| 1919 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1920 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1921 | return false; |
| 1922 | } |
| 1923 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame^] | 1924 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1925 | |
| 1926 | if (buffer == nullptr) |
| 1927 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1928 | context->handleError(Error(GL_INVALID_OPERATION, "Attempted to map buffer object zero.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1929 | return false; |
| 1930 | } |
| 1931 | |
| 1932 | if (access != GL_WRITE_ONLY_OES) |
| 1933 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1934 | context->handleError(Error(GL_INVALID_ENUM, "Non-write buffer mapping not supported.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1935 | return false; |
| 1936 | } |
| 1937 | |
| 1938 | if (buffer->isMapped()) |
| 1939 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1940 | context->handleError(Error(GL_INVALID_OPERATION, "Buffer is already mapped.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1941 | return false; |
| 1942 | } |
| 1943 | |
| 1944 | return true; |
| 1945 | } |
| 1946 | |
| 1947 | bool ValidateUnmapBufferOES(Context *context, GLenum target) |
| 1948 | { |
| 1949 | if (!context->getExtensions().mapBuffer) |
| 1950 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1951 | context->handleError(Error(GL_INVALID_OPERATION, "Map buffer extension not available.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1952 | return false; |
| 1953 | } |
| 1954 | |
| 1955 | return ValidateUnmapBufferBase(context, target); |
| 1956 | } |
| 1957 | |
| 1958 | bool ValidateMapBufferRangeEXT(Context *context, |
| 1959 | GLenum target, |
| 1960 | GLintptr offset, |
| 1961 | GLsizeiptr length, |
| 1962 | GLbitfield access) |
| 1963 | { |
| 1964 | if (!context->getExtensions().mapBufferRange) |
| 1965 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1966 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1967 | Error(GL_INVALID_OPERATION, "Map buffer range extension not available.")); |
| 1968 | return false; |
| 1969 | } |
| 1970 | |
| 1971 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 1972 | } |
| 1973 | |
| 1974 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
| 1975 | GLenum target, |
| 1976 | GLintptr offset, |
| 1977 | GLsizeiptr length) |
| 1978 | { |
| 1979 | if (!context->getExtensions().mapBufferRange) |
| 1980 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1981 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1982 | Error(GL_INVALID_OPERATION, "Map buffer range extension not available.")); |
| 1983 | return false; |
| 1984 | } |
| 1985 | |
| 1986 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 1987 | } |
| 1988 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 1989 | bool ValidateBindTexture(Context *context, GLenum target, GLuint texture) |
| 1990 | { |
| 1991 | Texture *textureObject = context->getTexture(texture); |
| 1992 | if (textureObject && textureObject->getTarget() != target && texture != 0) |
| 1993 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1994 | context->handleError(Error(GL_INVALID_OPERATION, "Invalid texture")); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 1995 | return false; |
| 1996 | } |
| 1997 | |
| 1998 | switch (target) |
| 1999 | { |
| 2000 | case GL_TEXTURE_2D: |
| 2001 | case GL_TEXTURE_CUBE_MAP: |
| 2002 | break; |
| 2003 | |
| 2004 | case GL_TEXTURE_3D: |
| 2005 | case GL_TEXTURE_2D_ARRAY: |
| 2006 | if (context->getClientVersion() < 3) |
| 2007 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2008 | context->handleError(Error(GL_INVALID_ENUM, "GLES 3.0 disabled")); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
| 2011 | break; |
| 2012 | case GL_TEXTURE_EXTERNAL_OES: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 2013 | if (!context->getExtensions().eglImageExternal && |
| 2014 | !context->getExtensions().eglStreamConsumerExternal) |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2015 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2016 | context->handleError( |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2017 | Error(GL_INVALID_ENUM, "External texture extension not enabled")); |
| 2018 | return false; |
| 2019 | } |
| 2020 | break; |
| 2021 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2022 | context->handleError(Error(GL_INVALID_ENUM, "Invalid target")); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2023 | return false; |
| 2024 | } |
| 2025 | |
| 2026 | return true; |
| 2027 | } |
| 2028 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2029 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 2030 | GLuint program, |
| 2031 | GLint location, |
| 2032 | const GLchar *name) |
| 2033 | { |
| 2034 | if (!context->getExtensions().bindUniformLocation) |
| 2035 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2036 | context->handleError( |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2037 | Error(GL_INVALID_OPERATION, "GL_CHROMIUM_bind_uniform_location is not available.")); |
| 2038 | return false; |
| 2039 | } |
| 2040 | |
| 2041 | Program *programObject = GetValidProgram(context, program); |
| 2042 | if (!programObject) |
| 2043 | { |
| 2044 | return false; |
| 2045 | } |
| 2046 | |
| 2047 | if (location < 0) |
| 2048 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2049 | context->handleError(Error(GL_INVALID_VALUE, "Location cannot be less than 0.")); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2050 | return false; |
| 2051 | } |
| 2052 | |
| 2053 | const Caps &caps = context->getCaps(); |
| 2054 | if (static_cast<size_t>(location) >= |
| 2055 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 2056 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2057 | context->handleError(Error(GL_INVALID_VALUE, |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2058 | "Location must be less than (MAX_VERTEX_UNIFORM_VECTORS + " |
| 2059 | "MAX_FRAGMENT_UNIFORM_VECTORS) * 4")); |
| 2060 | return false; |
| 2061 | } |
| 2062 | |
| 2063 | if (strncmp(name, "gl_", 3) == 0) |
| 2064 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2065 | context->handleError( |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2066 | Error(GL_INVALID_OPERATION, "Name cannot start with the reserved \"gl_\" prefix.")); |
| 2067 | return false; |
| 2068 | } |
| 2069 | |
| 2070 | return true; |
| 2071 | } |
| 2072 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2073 | bool ValidateCoverageModulationCHROMIUM(Context *context, GLenum components) |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 2074 | { |
| 2075 | if (!context->getExtensions().framebufferMixedSamples) |
| 2076 | { |
| 2077 | context->handleError( |
| 2078 | Error(GL_INVALID_OPERATION, "GL_CHROMIUM_framebuffer_mixed_samples is not available.")); |
| 2079 | return false; |
| 2080 | } |
| 2081 | switch (components) |
| 2082 | { |
| 2083 | case GL_RGB: |
| 2084 | case GL_RGBA: |
| 2085 | case GL_ALPHA: |
| 2086 | case GL_NONE: |
| 2087 | break; |
| 2088 | default: |
| 2089 | context->handleError( |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2090 | Error(GL_INVALID_ENUM, |
| 2091 | "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] | 2092 | return false; |
| 2093 | } |
| 2094 | |
| 2095 | return true; |
| 2096 | } |
| 2097 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2098 | } // namespace gl |