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 | |
| 50 | if (context->getState().isScissorTestEnabled()) |
| 51 | { |
| 52 | const Rectangle &scissor = context->getState().getScissor(); |
| 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 | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 498 | const gl::Framebuffer *framebuffer = context->getState().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 |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 966 | bool ValidES2ReadFormatType(Context *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: |
| 1025 | defaultFramebuffer = (context->getState().getTargetFramebuffer(GL_FRAMEBUFFER)->id() == 0); |
| 1026 | break; |
| 1027 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1028 | context->handleError(Error(GL_INVALID_ENUM, "Invalid framebuffer target")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1029 | return false; |
| 1030 | } |
| 1031 | |
| 1032 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, defaultFramebuffer); |
| 1033 | } |
| 1034 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1035 | bool ValidateBindVertexArrayOES(Context *context, GLuint array) |
| 1036 | { |
| 1037 | if (!context->getExtensions().vertexArrayObject) |
| 1038 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1039 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | return ValidateBindVertexArrayBase(context, array); |
| 1044 | } |
| 1045 | |
| 1046 | bool ValidateDeleteVertexArraysOES(Context *context, GLsizei n) |
| 1047 | { |
| 1048 | if (!context->getExtensions().vertexArrayObject) |
| 1049 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1050 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1051 | return false; |
| 1052 | } |
| 1053 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1054 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | bool ValidateGenVertexArraysOES(Context *context, GLsizei n) |
| 1058 | { |
| 1059 | if (!context->getExtensions().vertexArrayObject) |
| 1060 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1061 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1062 | return false; |
| 1063 | } |
| 1064 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1065 | return ValidateGenOrDelete(context, n); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | bool ValidateIsVertexArrayOES(Context *context) |
| 1069 | { |
| 1070 | if (!context->getExtensions().vertexArrayObject) |
| 1071 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1072 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1073 | return false; |
| 1074 | } |
| 1075 | |
| 1076 | return true; |
| 1077 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1078 | |
| 1079 | bool ValidateProgramBinaryOES(Context *context, |
| 1080 | GLuint program, |
| 1081 | GLenum binaryFormat, |
| 1082 | const void *binary, |
| 1083 | GLint length) |
| 1084 | { |
| 1085 | if (!context->getExtensions().getProgramBinary) |
| 1086 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1087 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1092 | } |
| 1093 | |
| 1094 | bool ValidateGetProgramBinaryOES(Context *context, |
| 1095 | GLuint program, |
| 1096 | GLsizei bufSize, |
| 1097 | GLsizei *length, |
| 1098 | GLenum *binaryFormat, |
| 1099 | void *binary) |
| 1100 | { |
| 1101 | if (!context->getExtensions().getProgramBinary) |
| 1102 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1103 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1104 | return false; |
| 1105 | } |
| 1106 | |
| 1107 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1108 | } |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1109 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1110 | static bool ValidDebugSource(GLenum source, bool mustBeThirdPartyOrApplication) |
| 1111 | { |
| 1112 | switch (source) |
| 1113 | { |
| 1114 | case GL_DEBUG_SOURCE_API: |
| 1115 | case GL_DEBUG_SOURCE_SHADER_COMPILER: |
| 1116 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: |
| 1117 | case GL_DEBUG_SOURCE_OTHER: |
| 1118 | // Only THIRD_PARTY and APPLICATION sources are allowed to be manually inserted |
| 1119 | return !mustBeThirdPartyOrApplication; |
| 1120 | |
| 1121 | case GL_DEBUG_SOURCE_THIRD_PARTY: |
| 1122 | case GL_DEBUG_SOURCE_APPLICATION: |
| 1123 | return true; |
| 1124 | |
| 1125 | default: |
| 1126 | return false; |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | static bool ValidDebugType(GLenum type) |
| 1131 | { |
| 1132 | switch (type) |
| 1133 | { |
| 1134 | case GL_DEBUG_TYPE_ERROR: |
| 1135 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: |
| 1136 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: |
| 1137 | case GL_DEBUG_TYPE_PERFORMANCE: |
| 1138 | case GL_DEBUG_TYPE_PORTABILITY: |
| 1139 | case GL_DEBUG_TYPE_OTHER: |
| 1140 | case GL_DEBUG_TYPE_MARKER: |
| 1141 | case GL_DEBUG_TYPE_PUSH_GROUP: |
| 1142 | case GL_DEBUG_TYPE_POP_GROUP: |
| 1143 | return true; |
| 1144 | |
| 1145 | default: |
| 1146 | return false; |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | static bool ValidDebugSeverity(GLenum severity) |
| 1151 | { |
| 1152 | switch (severity) |
| 1153 | { |
| 1154 | case GL_DEBUG_SEVERITY_HIGH: |
| 1155 | case GL_DEBUG_SEVERITY_MEDIUM: |
| 1156 | case GL_DEBUG_SEVERITY_LOW: |
| 1157 | case GL_DEBUG_SEVERITY_NOTIFICATION: |
| 1158 | return true; |
| 1159 | |
| 1160 | default: |
| 1161 | return false; |
| 1162 | } |
| 1163 | } |
| 1164 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1165 | bool ValidateDebugMessageControlKHR(Context *context, |
| 1166 | GLenum source, |
| 1167 | GLenum type, |
| 1168 | GLenum severity, |
| 1169 | GLsizei count, |
| 1170 | const GLuint *ids, |
| 1171 | GLboolean enabled) |
| 1172 | { |
| 1173 | if (!context->getExtensions().debug) |
| 1174 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1175 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1176 | return false; |
| 1177 | } |
| 1178 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1179 | if (!ValidDebugSource(source, false) && source != GL_DONT_CARE) |
| 1180 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1181 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug source.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1182 | return false; |
| 1183 | } |
| 1184 | |
| 1185 | if (!ValidDebugType(type) && type != GL_DONT_CARE) |
| 1186 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1187 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug type.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1188 | return false; |
| 1189 | } |
| 1190 | |
| 1191 | if (!ValidDebugSeverity(severity) && severity != GL_DONT_CARE) |
| 1192 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1193 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug severity.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1194 | return false; |
| 1195 | } |
| 1196 | |
| 1197 | if (count > 0) |
| 1198 | { |
| 1199 | if (source == GL_DONT_CARE || type == GL_DONT_CARE) |
| 1200 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1201 | context->handleError(Error( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1202 | GL_INVALID_OPERATION, |
| 1203 | "If count is greater than zero, source and severity cannot be GL_DONT_CARE.")); |
| 1204 | return false; |
| 1205 | } |
| 1206 | |
| 1207 | if (severity != GL_DONT_CARE) |
| 1208 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1209 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1210 | Error(GL_INVALID_OPERATION, |
| 1211 | "If count is greater than zero, severity must be GL_DONT_CARE.")); |
| 1212 | return false; |
| 1213 | } |
| 1214 | } |
| 1215 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1216 | return true; |
| 1217 | } |
| 1218 | |
| 1219 | bool ValidateDebugMessageInsertKHR(Context *context, |
| 1220 | GLenum source, |
| 1221 | GLenum type, |
| 1222 | GLuint id, |
| 1223 | GLenum severity, |
| 1224 | GLsizei length, |
| 1225 | const GLchar *buf) |
| 1226 | { |
| 1227 | if (!context->getExtensions().debug) |
| 1228 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1229 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1230 | return false; |
| 1231 | } |
| 1232 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1233 | if (!context->getState().getDebug().isOutputEnabled()) |
| 1234 | { |
| 1235 | // If the DEBUG_OUTPUT state is disabled calls to DebugMessageInsert are discarded and do |
| 1236 | // not generate an error. |
| 1237 | return false; |
| 1238 | } |
| 1239 | |
| 1240 | if (!ValidDebugSeverity(severity)) |
| 1241 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1242 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug severity.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1243 | return false; |
| 1244 | } |
| 1245 | |
| 1246 | if (!ValidDebugType(type)) |
| 1247 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1248 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug type.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1249 | return false; |
| 1250 | } |
| 1251 | |
| 1252 | if (!ValidDebugSource(source, true)) |
| 1253 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1254 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug source.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1255 | return false; |
| 1256 | } |
| 1257 | |
| 1258 | size_t messageLength = (length < 0) ? strlen(buf) : length; |
| 1259 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 1260 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1261 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1262 | Error(GL_INVALID_VALUE, "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH.")); |
| 1263 | return false; |
| 1264 | } |
| 1265 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1266 | return true; |
| 1267 | } |
| 1268 | |
| 1269 | bool ValidateDebugMessageCallbackKHR(Context *context, |
| 1270 | GLDEBUGPROCKHR callback, |
| 1271 | const void *userParam) |
| 1272 | { |
| 1273 | if (!context->getExtensions().debug) |
| 1274 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1275 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1276 | return false; |
| 1277 | } |
| 1278 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1279 | return true; |
| 1280 | } |
| 1281 | |
| 1282 | bool ValidateGetDebugMessageLogKHR(Context *context, |
| 1283 | GLuint count, |
| 1284 | GLsizei bufSize, |
| 1285 | GLenum *sources, |
| 1286 | GLenum *types, |
| 1287 | GLuint *ids, |
| 1288 | GLenum *severities, |
| 1289 | GLsizei *lengths, |
| 1290 | GLchar *messageLog) |
| 1291 | { |
| 1292 | if (!context->getExtensions().debug) |
| 1293 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1294 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1295 | return false; |
| 1296 | } |
| 1297 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1298 | if (bufSize < 0 && messageLog != nullptr) |
| 1299 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1300 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1301 | Error(GL_INVALID_VALUE, "bufSize must be positive if messageLog is not null.")); |
| 1302 | return false; |
| 1303 | } |
| 1304 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1305 | return true; |
| 1306 | } |
| 1307 | |
| 1308 | bool ValidatePushDebugGroupKHR(Context *context, |
| 1309 | GLenum source, |
| 1310 | GLuint id, |
| 1311 | GLsizei length, |
| 1312 | const GLchar *message) |
| 1313 | { |
| 1314 | if (!context->getExtensions().debug) |
| 1315 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1316 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1317 | return false; |
| 1318 | } |
| 1319 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1320 | if (!ValidDebugSource(source, true)) |
| 1321 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1322 | context->handleError(Error(GL_INVALID_ENUM, "Invalid debug source.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1323 | return false; |
| 1324 | } |
| 1325 | |
| 1326 | size_t messageLength = (length < 0) ? strlen(message) : length; |
| 1327 | if (messageLength > context->getExtensions().maxDebugMessageLength) |
| 1328 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1329 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1330 | Error(GL_INVALID_VALUE, "Message length is larger than GL_MAX_DEBUG_MESSAGE_LENGTH.")); |
| 1331 | return false; |
| 1332 | } |
| 1333 | |
| 1334 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
| 1335 | if (currentStackSize >= context->getExtensions().maxDebugGroupStackDepth) |
| 1336 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1337 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1338 | Error(GL_STACK_OVERFLOW, |
| 1339 | "Cannot push more than GL_MAX_DEBUG_GROUP_STACK_DEPTH debug groups.")); |
| 1340 | return false; |
| 1341 | } |
| 1342 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1343 | return true; |
| 1344 | } |
| 1345 | |
| 1346 | bool ValidatePopDebugGroupKHR(Context *context) |
| 1347 | { |
| 1348 | if (!context->getExtensions().debug) |
| 1349 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1350 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1351 | return false; |
| 1352 | } |
| 1353 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1354 | size_t currentStackSize = context->getState().getDebug().getGroupStackDepth(); |
| 1355 | if (currentStackSize <= 1) |
| 1356 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1357 | context->handleError(Error(GL_STACK_UNDERFLOW, "Cannot pop the default debug group.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1358 | return false; |
| 1359 | } |
| 1360 | |
| 1361 | return true; |
| 1362 | } |
| 1363 | |
| 1364 | static bool ValidateObjectIdentifierAndName(Context *context, GLenum identifier, GLuint name) |
| 1365 | { |
| 1366 | switch (identifier) |
| 1367 | { |
| 1368 | case GL_BUFFER: |
| 1369 | if (context->getBuffer(name) == nullptr) |
| 1370 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1371 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid buffer.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1372 | return false; |
| 1373 | } |
| 1374 | return true; |
| 1375 | |
| 1376 | case GL_SHADER: |
| 1377 | if (context->getShader(name) == nullptr) |
| 1378 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1379 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid shader.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1380 | return false; |
| 1381 | } |
| 1382 | return true; |
| 1383 | |
| 1384 | case GL_PROGRAM: |
| 1385 | if (context->getProgram(name) == nullptr) |
| 1386 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1387 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid program.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1388 | return false; |
| 1389 | } |
| 1390 | return true; |
| 1391 | |
| 1392 | case GL_VERTEX_ARRAY: |
| 1393 | if (context->getVertexArray(name) == nullptr) |
| 1394 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1395 | 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] | 1396 | return false; |
| 1397 | } |
| 1398 | return true; |
| 1399 | |
| 1400 | case GL_QUERY: |
| 1401 | if (context->getQuery(name) == nullptr) |
| 1402 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1403 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid query.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1404 | return false; |
| 1405 | } |
| 1406 | return true; |
| 1407 | |
| 1408 | case GL_TRANSFORM_FEEDBACK: |
| 1409 | if (context->getTransformFeedback(name) == nullptr) |
| 1410 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1411 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1412 | Error(GL_INVALID_VALUE, "name is not a valid transform feedback.")); |
| 1413 | return false; |
| 1414 | } |
| 1415 | return true; |
| 1416 | |
| 1417 | case GL_SAMPLER: |
| 1418 | if (context->getSampler(name) == nullptr) |
| 1419 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1420 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid sampler.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1421 | return false; |
| 1422 | } |
| 1423 | return true; |
| 1424 | |
| 1425 | case GL_TEXTURE: |
| 1426 | if (context->getTexture(name) == nullptr) |
| 1427 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1428 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid texture.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1429 | return false; |
| 1430 | } |
| 1431 | return true; |
| 1432 | |
| 1433 | case GL_RENDERBUFFER: |
| 1434 | if (context->getRenderbuffer(name) == nullptr) |
| 1435 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1436 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid renderbuffer.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1437 | return false; |
| 1438 | } |
| 1439 | return true; |
| 1440 | |
| 1441 | case GL_FRAMEBUFFER: |
| 1442 | if (context->getFramebuffer(name) == nullptr) |
| 1443 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1444 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid framebuffer.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1445 | return false; |
| 1446 | } |
| 1447 | return true; |
| 1448 | |
| 1449 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1450 | context->handleError(Error(GL_INVALID_ENUM, "Invalid identifier.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1451 | return false; |
| 1452 | } |
| 1453 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1454 | return true; |
| 1455 | } |
| 1456 | |
| 1457 | bool ValidateObjectLabelKHR(Context *context, |
| 1458 | GLenum identifier, |
| 1459 | GLuint name, |
| 1460 | GLsizei length, |
| 1461 | const GLchar *label) |
| 1462 | { |
| 1463 | if (!context->getExtensions().debug) |
| 1464 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1465 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1466 | return false; |
| 1467 | } |
| 1468 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1469 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 1470 | { |
| 1471 | return false; |
| 1472 | } |
| 1473 | |
| 1474 | size_t labelLength = (length < 0) ? strlen(label) : length; |
| 1475 | if (labelLength > context->getExtensions().maxLabelLength) |
| 1476 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1477 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1478 | Error(GL_INVALID_VALUE, "Label length is larger than GL_MAX_LABEL_LENGTH.")); |
| 1479 | return false; |
| 1480 | } |
| 1481 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1482 | return true; |
| 1483 | } |
| 1484 | |
| 1485 | bool ValidateGetObjectLabelKHR(Context *context, |
| 1486 | GLenum identifier, |
| 1487 | GLuint name, |
| 1488 | GLsizei bufSize, |
| 1489 | GLsizei *length, |
| 1490 | GLchar *label) |
| 1491 | { |
| 1492 | if (!context->getExtensions().debug) |
| 1493 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1494 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1495 | return false; |
| 1496 | } |
| 1497 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1498 | if (bufSize < 0) |
| 1499 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1500 | context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1501 | return false; |
| 1502 | } |
| 1503 | |
| 1504 | if (!ValidateObjectIdentifierAndName(context, identifier, name)) |
| 1505 | { |
| 1506 | return false; |
| 1507 | } |
| 1508 | |
| 1509 | // Can no-op if bufSize is zero. |
| 1510 | return bufSize > 0; |
| 1511 | } |
| 1512 | |
| 1513 | static bool ValidateObjectPtrName(Context *context, const void *ptr) |
| 1514 | { |
| 1515 | if (context->getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))) == nullptr) |
| 1516 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1517 | context->handleError(Error(GL_INVALID_VALUE, "name is not a valid sync.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1518 | return false; |
| 1519 | } |
| 1520 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1521 | return true; |
| 1522 | } |
| 1523 | |
| 1524 | bool ValidateObjectPtrLabelKHR(Context *context, |
| 1525 | const void *ptr, |
| 1526 | GLsizei length, |
| 1527 | const GLchar *label) |
| 1528 | { |
| 1529 | if (!context->getExtensions().debug) |
| 1530 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1531 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1532 | return false; |
| 1533 | } |
| 1534 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1535 | if (!ValidateObjectPtrName(context, ptr)) |
| 1536 | { |
| 1537 | return false; |
| 1538 | } |
| 1539 | |
| 1540 | size_t labelLength = (length < 0) ? strlen(label) : length; |
| 1541 | if (labelLength > context->getExtensions().maxLabelLength) |
| 1542 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1543 | context->handleError( |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1544 | Error(GL_INVALID_VALUE, "Label length is larger than GL_MAX_LABEL_LENGTH.")); |
| 1545 | return false; |
| 1546 | } |
| 1547 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1548 | return true; |
| 1549 | } |
| 1550 | |
| 1551 | bool ValidateGetObjectPtrLabelKHR(Context *context, |
| 1552 | const void *ptr, |
| 1553 | GLsizei bufSize, |
| 1554 | GLsizei *length, |
| 1555 | GLchar *label) |
| 1556 | { |
| 1557 | if (!context->getExtensions().debug) |
| 1558 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1559 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1560 | return false; |
| 1561 | } |
| 1562 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1563 | if (bufSize < 0) |
| 1564 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1565 | context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1566 | return false; |
| 1567 | } |
| 1568 | |
| 1569 | if (!ValidateObjectPtrName(context, ptr)) |
| 1570 | { |
| 1571 | return false; |
| 1572 | } |
| 1573 | |
| 1574 | // Can no-op if bufSize is zero. |
| 1575 | return bufSize > 0; |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | bool ValidateGetPointervKHR(Context *context, GLenum pname, void **params) |
| 1579 | { |
| 1580 | if (!context->getExtensions().debug) |
| 1581 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1582 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not enabled")); |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1583 | return false; |
| 1584 | } |
| 1585 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1586 | // TODO: represent this in Context::getQueryParameterInfo. |
| 1587 | switch (pname) |
| 1588 | { |
| 1589 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 1590 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 1591 | break; |
| 1592 | |
| 1593 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1594 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname.")); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1595 | return false; |
| 1596 | } |
| 1597 | |
Geoff Lang | e102fee | 2015-12-10 11:23:30 -0500 | [diff] [blame] | 1598 | return true; |
| 1599 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1600 | |
| 1601 | bool ValidateBlitFramebufferANGLE(Context *context, |
| 1602 | GLint srcX0, |
| 1603 | GLint srcY0, |
| 1604 | GLint srcX1, |
| 1605 | GLint srcY1, |
| 1606 | GLint dstX0, |
| 1607 | GLint dstY0, |
| 1608 | GLint dstX1, |
| 1609 | GLint dstY1, |
| 1610 | GLbitfield mask, |
| 1611 | GLenum filter) |
| 1612 | { |
| 1613 | if (!context->getExtensions().framebufferBlit) |
| 1614 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1615 | context->handleError(Error(GL_INVALID_OPERATION, "Blit extension not available.")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1616 | return false; |
| 1617 | } |
| 1618 | |
| 1619 | if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0) |
| 1620 | { |
| 1621 | // TODO(jmadill): Determine if this should be available on other implementations. |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1622 | context->handleError(Error( |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1623 | GL_INVALID_OPERATION, |
| 1624 | "Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.")); |
| 1625 | return false; |
| 1626 | } |
| 1627 | |
| 1628 | if (filter == GL_LINEAR) |
| 1629 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1630 | 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] | 1631 | return false; |
| 1632 | } |
| 1633 | |
| 1634 | const Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 1635 | const Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
| 1636 | |
| 1637 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1638 | { |
| 1639 | const FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 1640 | const FramebufferAttachment *drawColorAttachment = drawFramebuffer->getFirstColorbuffer(); |
| 1641 | |
| 1642 | if (readColorAttachment && drawColorAttachment) |
| 1643 | { |
| 1644 | if (!(readColorAttachment->type() == GL_TEXTURE && |
| 1645 | readColorAttachment->getTextureImageIndex().type == GL_TEXTURE_2D) && |
| 1646 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 1647 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 1648 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1649 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1650 | return false; |
| 1651 | } |
| 1652 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1653 | for (size_t drawbufferIdx = 0; |
| 1654 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1655 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1656 | const FramebufferAttachment *attachment = |
| 1657 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1658 | if (attachment) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1659 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1660 | if (!(attachment->type() == GL_TEXTURE && |
| 1661 | attachment->getTextureImageIndex().type == GL_TEXTURE_2D) && |
| 1662 | attachment->type() != GL_RENDERBUFFER && |
| 1663 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
| 1664 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1665 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1666 | return false; |
| 1667 | } |
| 1668 | |
| 1669 | // Return an error if the destination formats do not match |
| 1670 | if (attachment->getInternalFormat() != readColorAttachment->getInternalFormat()) |
| 1671 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1672 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1673 | return false; |
| 1674 | } |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | int readSamples = readFramebuffer->getSamples(context->getData()); |
| 1679 | |
| 1680 | if (readSamples != 0 && |
| 1681 | IsPartialBlit(context, readColorAttachment, drawColorAttachment, srcX0, srcY0, |
| 1682 | srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 1683 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1684 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1685 | return false; |
| 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 1691 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1692 | for (size_t i = 0; i < 2; i++) |
| 1693 | { |
| 1694 | if (mask & masks[i]) |
| 1695 | { |
| 1696 | const FramebufferAttachment *readBuffer = |
| 1697 | readFramebuffer->getAttachment(attachments[i]); |
| 1698 | const FramebufferAttachment *drawBuffer = |
| 1699 | drawFramebuffer->getAttachment(attachments[i]); |
| 1700 | |
| 1701 | if (readBuffer && drawBuffer) |
| 1702 | { |
| 1703 | if (IsPartialBlit(context, readBuffer, drawBuffer, srcX0, srcY0, srcX1, srcY1, |
| 1704 | dstX0, dstY0, dstX1, dstY1)) |
| 1705 | { |
| 1706 | // only whole-buffer copies are permitted |
| 1707 | ERR( |
| 1708 | "Only whole-buffer depth and stencil blits are supported by this " |
| 1709 | "implementation."); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1710 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1711 | return false; |
| 1712 | } |
| 1713 | |
| 1714 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 1715 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1716 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1717 | return false; |
| 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 1724 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1725 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1726 | |
| 1727 | bool ValidateClear(ValidationContext *context, GLbitfield mask) |
| 1728 | { |
| 1729 | const Framebuffer *framebufferObject = context->getState().getDrawFramebuffer(); |
| 1730 | ASSERT(framebufferObject); |
| 1731 | |
| 1732 | if (framebufferObject->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
| 1733 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1734 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1735 | return false; |
| 1736 | } |
| 1737 | |
| 1738 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) |
| 1739 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1740 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1741 | return false; |
| 1742 | } |
| 1743 | |
| 1744 | return true; |
| 1745 | } |
| 1746 | |
| 1747 | bool ValidateDrawBuffersEXT(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 1748 | { |
| 1749 | if (!context->getExtensions().drawBuffers) |
| 1750 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1751 | context->handleError(Error(GL_INVALID_OPERATION, "Extension not supported.")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1752 | return false; |
| 1753 | } |
| 1754 | |
| 1755 | return ValidateDrawBuffersBase(context, n, bufs); |
| 1756 | } |
| 1757 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1758 | bool ValidateTexImage2D(Context *context, |
| 1759 | GLenum target, |
| 1760 | GLint level, |
| 1761 | GLint internalformat, |
| 1762 | GLsizei width, |
| 1763 | GLsizei height, |
| 1764 | GLint border, |
| 1765 | GLenum format, |
| 1766 | GLenum type, |
| 1767 | const GLvoid *pixels) |
| 1768 | { |
| 1769 | if (context->getClientVersion() < 3) |
| 1770 | { |
| 1771 | return ValidateES2TexImageParameters(context, target, level, internalformat, false, false, |
| 1772 | 0, 0, width, height, border, format, type, pixels); |
| 1773 | } |
| 1774 | |
| 1775 | ASSERT(context->getClientVersion() >= 3); |
| 1776 | return ValidateES3TexImage2DParameters(context, target, level, internalformat, false, false, 0, |
| 1777 | 0, 0, width, height, 1, border, format, type, pixels); |
| 1778 | } |
| 1779 | |
| 1780 | bool ValidateTexSubImage2D(Context *context, |
| 1781 | GLenum target, |
| 1782 | GLint level, |
| 1783 | GLint xoffset, |
| 1784 | GLint yoffset, |
| 1785 | GLsizei width, |
| 1786 | GLsizei height, |
| 1787 | GLenum format, |
| 1788 | GLenum type, |
| 1789 | const GLvoid *pixels) |
| 1790 | { |
| 1791 | |
| 1792 | if (context->getClientVersion() < 3) |
| 1793 | { |
| 1794 | return ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1795 | yoffset, width, height, 0, format, type, pixels); |
| 1796 | } |
| 1797 | |
| 1798 | ASSERT(context->getClientVersion() >= 3); |
| 1799 | return ValidateES3TexImage2DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1800 | yoffset, 0, width, height, 1, 0, format, type, pixels); |
| 1801 | } |
| 1802 | |
| 1803 | bool ValidateCompressedTexImage2D(Context *context, |
| 1804 | GLenum target, |
| 1805 | GLint level, |
| 1806 | GLenum internalformat, |
| 1807 | GLsizei width, |
| 1808 | GLsizei height, |
| 1809 | GLint border, |
| 1810 | GLsizei imageSize, |
| 1811 | const GLvoid *data) |
| 1812 | { |
| 1813 | if (context->getClientVersion() < 3) |
| 1814 | { |
| 1815 | if (!ValidateES2TexImageParameters(context, target, level, internalformat, true, false, 0, |
| 1816 | 0, width, height, border, GL_NONE, GL_NONE, data)) |
| 1817 | { |
| 1818 | return false; |
| 1819 | } |
| 1820 | } |
| 1821 | else |
| 1822 | { |
| 1823 | ASSERT(context->getClientVersion() >= 3); |
| 1824 | if (!ValidateES3TexImage2DParameters(context, target, level, internalformat, true, false, 0, |
| 1825 | 0, 0, width, height, 1, border, GL_NONE, GL_NONE, |
| 1826 | data)) |
| 1827 | { |
| 1828 | return false; |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
| 1833 | if (imageSize < 0 || |
| 1834 | static_cast<GLuint>(imageSize) != |
| 1835 | formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height)) |
| 1836 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1837 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1838 | return false; |
| 1839 | } |
| 1840 | |
| 1841 | return true; |
| 1842 | } |
| 1843 | |
| 1844 | bool ValidateCompressedTexSubImage2D(Context *context, |
| 1845 | GLenum target, |
| 1846 | GLint level, |
| 1847 | GLint xoffset, |
| 1848 | GLint yoffset, |
| 1849 | GLsizei width, |
| 1850 | GLsizei height, |
| 1851 | GLenum format, |
| 1852 | GLsizei imageSize, |
| 1853 | const GLvoid *data) |
| 1854 | { |
| 1855 | if (context->getClientVersion() < 3) |
| 1856 | { |
| 1857 | if (!ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true, xoffset, |
| 1858 | yoffset, width, height, 0, GL_NONE, GL_NONE, data)) |
| 1859 | { |
| 1860 | return false; |
| 1861 | } |
| 1862 | } |
| 1863 | else |
| 1864 | { |
| 1865 | ASSERT(context->getClientVersion() >= 3); |
| 1866 | if (!ValidateES3TexImage2DParameters(context, target, level, GL_NONE, true, true, xoffset, |
| 1867 | yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, |
| 1868 | data)) |
| 1869 | { |
| 1870 | return false; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | const InternalFormat &formatInfo = GetInternalFormatInfo(format); |
| 1875 | if (imageSize < 0 || |
| 1876 | static_cast<GLuint>(imageSize) != |
| 1877 | formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height)) |
| 1878 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1879 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1880 | return false; |
| 1881 | } |
| 1882 | |
| 1883 | return true; |
| 1884 | } |
| 1885 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1886 | bool ValidateGetBufferPointervOES(Context *context, GLenum target, GLenum pname, void **params) |
| 1887 | { |
| 1888 | if (!context->getExtensions().mapBuffer) |
| 1889 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1890 | context->handleError(Error(GL_INVALID_OPERATION, "Map buffer extension not available.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1891 | return false; |
| 1892 | } |
| 1893 | |
| 1894 | return ValidateGetBufferPointervBase(context, target, pname, params); |
| 1895 | } |
| 1896 | |
| 1897 | bool ValidateMapBufferOES(Context *context, GLenum target, GLenum access) |
| 1898 | { |
| 1899 | if (!context->getExtensions().mapBuffer) |
| 1900 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1901 | context->handleError(Error(GL_INVALID_OPERATION, "Map buffer extension not available.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1902 | return false; |
| 1903 | } |
| 1904 | |
| 1905 | if (!ValidBufferTarget(context, target)) |
| 1906 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1907 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1908 | return false; |
| 1909 | } |
| 1910 | |
| 1911 | Buffer *buffer = context->getState().getTargetBuffer(target); |
| 1912 | |
| 1913 | if (buffer == nullptr) |
| 1914 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1915 | context->handleError(Error(GL_INVALID_OPERATION, "Attempted to map buffer object zero.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1916 | return false; |
| 1917 | } |
| 1918 | |
| 1919 | if (access != GL_WRITE_ONLY_OES) |
| 1920 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1921 | context->handleError(Error(GL_INVALID_ENUM, "Non-write buffer mapping not supported.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1922 | return false; |
| 1923 | } |
| 1924 | |
| 1925 | if (buffer->isMapped()) |
| 1926 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1927 | context->handleError(Error(GL_INVALID_OPERATION, "Buffer is already mapped.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1928 | return false; |
| 1929 | } |
| 1930 | |
| 1931 | return true; |
| 1932 | } |
| 1933 | |
| 1934 | bool ValidateUnmapBufferOES(Context *context, GLenum target) |
| 1935 | { |
| 1936 | if (!context->getExtensions().mapBuffer) |
| 1937 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1938 | context->handleError(Error(GL_INVALID_OPERATION, "Map buffer extension not available.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1939 | return false; |
| 1940 | } |
| 1941 | |
| 1942 | return ValidateUnmapBufferBase(context, target); |
| 1943 | } |
| 1944 | |
| 1945 | bool ValidateMapBufferRangeEXT(Context *context, |
| 1946 | GLenum target, |
| 1947 | GLintptr offset, |
| 1948 | GLsizeiptr length, |
| 1949 | GLbitfield access) |
| 1950 | { |
| 1951 | if (!context->getExtensions().mapBufferRange) |
| 1952 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1953 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1954 | Error(GL_INVALID_OPERATION, "Map buffer range extension not available.")); |
| 1955 | return false; |
| 1956 | } |
| 1957 | |
| 1958 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 1959 | } |
| 1960 | |
| 1961 | bool ValidateFlushMappedBufferRangeEXT(Context *context, |
| 1962 | GLenum target, |
| 1963 | GLintptr offset, |
| 1964 | GLsizeiptr length) |
| 1965 | { |
| 1966 | if (!context->getExtensions().mapBufferRange) |
| 1967 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1968 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1969 | Error(GL_INVALID_OPERATION, "Map buffer range extension not available.")); |
| 1970 | return false; |
| 1971 | } |
| 1972 | |
| 1973 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 1974 | } |
| 1975 | |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 1976 | bool ValidateBindTexture(Context *context, GLenum target, GLuint texture) |
| 1977 | { |
| 1978 | Texture *textureObject = context->getTexture(texture); |
| 1979 | if (textureObject && textureObject->getTarget() != target && texture != 0) |
| 1980 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1981 | context->handleError(Error(GL_INVALID_OPERATION, "Invalid texture")); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 1982 | return false; |
| 1983 | } |
| 1984 | |
| 1985 | switch (target) |
| 1986 | { |
| 1987 | case GL_TEXTURE_2D: |
| 1988 | case GL_TEXTURE_CUBE_MAP: |
| 1989 | break; |
| 1990 | |
| 1991 | case GL_TEXTURE_3D: |
| 1992 | case GL_TEXTURE_2D_ARRAY: |
| 1993 | if (context->getClientVersion() < 3) |
| 1994 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1995 | context->handleError(Error(GL_INVALID_ENUM, "GLES 3.0 disabled")); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 1996 | return false; |
| 1997 | } |
| 1998 | break; |
| 1999 | case GL_TEXTURE_EXTERNAL_OES: |
| 2000 | if (!context->getExtensions().eglStreamConsumerExternal) |
| 2001 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2002 | context->handleError( |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2003 | Error(GL_INVALID_ENUM, "External texture extension not enabled")); |
| 2004 | return false; |
| 2005 | } |
| 2006 | break; |
| 2007 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2008 | context->handleError(Error(GL_INVALID_ENUM, "Invalid target")); |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
| 2011 | |
| 2012 | return true; |
| 2013 | } |
| 2014 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2015 | bool ValidateBindUniformLocationCHROMIUM(Context *context, |
| 2016 | GLuint program, |
| 2017 | GLint location, |
| 2018 | const GLchar *name) |
| 2019 | { |
| 2020 | if (!context->getExtensions().bindUniformLocation) |
| 2021 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2022 | context->handleError( |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2023 | Error(GL_INVALID_OPERATION, "GL_CHROMIUM_bind_uniform_location is not available.")); |
| 2024 | return false; |
| 2025 | } |
| 2026 | |
| 2027 | Program *programObject = GetValidProgram(context, program); |
| 2028 | if (!programObject) |
| 2029 | { |
| 2030 | return false; |
| 2031 | } |
| 2032 | |
| 2033 | if (location < 0) |
| 2034 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2035 | context->handleError(Error(GL_INVALID_VALUE, "Location cannot be less than 0.")); |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2036 | return false; |
| 2037 | } |
| 2038 | |
| 2039 | const Caps &caps = context->getCaps(); |
| 2040 | if (static_cast<size_t>(location) >= |
| 2041 | (caps.maxVertexUniformVectors + caps.maxFragmentUniformVectors) * 4) |
| 2042 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2043 | context->handleError(Error(GL_INVALID_VALUE, |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2044 | "Location must be less than (MAX_VERTEX_UNIFORM_VECTORS + " |
| 2045 | "MAX_FRAGMENT_UNIFORM_VECTORS) * 4")); |
| 2046 | return false; |
| 2047 | } |
| 2048 | |
| 2049 | if (strncmp(name, "gl_", 3) == 0) |
| 2050 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2051 | context->handleError( |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2052 | Error(GL_INVALID_OPERATION, "Name cannot start with the reserved \"gl_\" prefix.")); |
| 2053 | return false; |
| 2054 | } |
| 2055 | |
| 2056 | return true; |
| 2057 | } |
| 2058 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame^] | 2059 | bool ValidateCoverageModulationCHROMIUM(Context* context, GLenum components) |
| 2060 | { |
| 2061 | if (!context->getExtensions().framebufferMixedSamples) |
| 2062 | { |
| 2063 | context->handleError( |
| 2064 | Error(GL_INVALID_OPERATION, "GL_CHROMIUM_framebuffer_mixed_samples is not available.")); |
| 2065 | return false; |
| 2066 | } |
| 2067 | switch (components) |
| 2068 | { |
| 2069 | case GL_RGB: |
| 2070 | case GL_RGBA: |
| 2071 | case GL_ALPHA: |
| 2072 | case GL_NONE: |
| 2073 | break; |
| 2074 | default: |
| 2075 | context->handleError( |
| 2076 | Error(GL_INVALID_ENUM, "GLenum components is not one of GL_RGB, GL_RGBA, GL_ALPHA or GL_NONE.")); |
| 2077 | return false; |
| 2078 | } |
| 2079 | |
| 2080 | return true; |
| 2081 | } |
| 2082 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2083 | } // namespace gl |