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 | // validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES3.h" |
| 10 | #include "libANGLE/validationES.h" |
| 11 | #include "libANGLE/Context.h" |
| 12 | #include "libANGLE/Texture.h" |
| 13 | #include "libANGLE/Framebuffer.h" |
| 14 | #include "libANGLE/Renderbuffer.h" |
| 15 | #include "libANGLE/formatutils.h" |
| 16 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 17 | |
| 18 | #include "common/mathutil.h" |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 19 | #include "common/utilities.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 20 | |
| 21 | namespace gl |
| 22 | { |
| 23 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 24 | struct ES3FormatCombination |
| 25 | { |
| 26 | GLenum internalFormat; |
| 27 | GLenum format; |
| 28 | GLenum type; |
| 29 | }; |
| 30 | |
| 31 | bool operator<(const ES3FormatCombination& a, const ES3FormatCombination& b) |
| 32 | { |
| 33 | return memcmp(&a, &b, sizeof(ES3FormatCombination)) < 0; |
| 34 | } |
| 35 | |
| 36 | typedef std::set<ES3FormatCombination> ES3FormatCombinationSet; |
| 37 | |
| 38 | static inline void InsertES3FormatCombo(ES3FormatCombinationSet *set, GLenum internalFormat, GLenum format, GLenum type) |
| 39 | { |
| 40 | ES3FormatCombination info; |
| 41 | info.internalFormat = internalFormat; |
| 42 | info.format = format; |
| 43 | info.type = type; |
| 44 | set->insert(info); |
| 45 | } |
| 46 | |
| 47 | ES3FormatCombinationSet BuildES3FormatSet() |
| 48 | { |
| 49 | ES3FormatCombinationSet set; |
| 50 | |
| 51 | // Format combinations from ES 3.0.1 spec, table 3.2 |
| 52 | |
| 53 | // | Internal format | Format | Type | |
| 54 | // | | | | |
| 55 | InsertES3FormatCombo(&set, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 56 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 57 | InsertES3FormatCombo(&set, GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 58 | InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 59 | InsertES3FormatCombo(&set, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ); |
| 60 | InsertES3FormatCombo(&set, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ); |
| 61 | InsertES3FormatCombo(&set, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 62 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 63 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ); |
| 64 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ); |
| 65 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT_OES ); |
| 66 | InsertES3FormatCombo(&set, GL_RGBA32F, GL_RGBA, GL_FLOAT ); |
| 67 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_FLOAT ); |
| 68 | InsertES3FormatCombo(&set, GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ); |
| 69 | InsertES3FormatCombo(&set, GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ); |
| 70 | InsertES3FormatCombo(&set, GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ); |
| 71 | InsertES3FormatCombo(&set, GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ); |
| 72 | InsertES3FormatCombo(&set, GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ); |
| 73 | InsertES3FormatCombo(&set, GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ); |
| 74 | InsertES3FormatCombo(&set, GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 75 | InsertES3FormatCombo(&set, GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ); |
| 76 | InsertES3FormatCombo(&set, GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ); |
| 77 | InsertES3FormatCombo(&set, GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ); |
| 78 | InsertES3FormatCombo(&set, GL_RGB8_SNORM, GL_RGB, GL_BYTE ); |
| 79 | InsertES3FormatCombo(&set, GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ); |
| 80 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ); |
| 81 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ); |
| 82 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_HALF_FLOAT ); |
| 83 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_HALF_FLOAT_OES ); |
| 84 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ); |
| 85 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT_OES ); |
| 86 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ); |
| 87 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT_OES ); |
| 88 | InsertES3FormatCombo(&set, GL_RGB32F, GL_RGB, GL_FLOAT ); |
| 89 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_FLOAT ); |
| 90 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ); |
| 91 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_FLOAT ); |
| 92 | InsertES3FormatCombo(&set, GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ); |
| 93 | InsertES3FormatCombo(&set, GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ); |
| 94 | InsertES3FormatCombo(&set, GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ); |
| 95 | InsertES3FormatCombo(&set, GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ); |
| 96 | InsertES3FormatCombo(&set, GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ); |
| 97 | InsertES3FormatCombo(&set, GL_RGB32I, GL_RGB_INTEGER, GL_INT ); |
| 98 | InsertES3FormatCombo(&set, GL_RG8, GL_RG, GL_UNSIGNED_BYTE ); |
| 99 | InsertES3FormatCombo(&set, GL_RG8_SNORM, GL_RG, GL_BYTE ); |
| 100 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_HALF_FLOAT ); |
| 101 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_HALF_FLOAT_OES ); |
| 102 | InsertES3FormatCombo(&set, GL_RG32F, GL_RG, GL_FLOAT ); |
| 103 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_FLOAT ); |
| 104 | InsertES3FormatCombo(&set, GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ); |
| 105 | InsertES3FormatCombo(&set, GL_RG8I, GL_RG_INTEGER, GL_BYTE ); |
| 106 | InsertES3FormatCombo(&set, GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ); |
| 107 | InsertES3FormatCombo(&set, GL_RG16I, GL_RG_INTEGER, GL_SHORT ); |
| 108 | InsertES3FormatCombo(&set, GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ); |
| 109 | InsertES3FormatCombo(&set, GL_RG32I, GL_RG_INTEGER, GL_INT ); |
| 110 | InsertES3FormatCombo(&set, GL_R8, GL_RED, GL_UNSIGNED_BYTE ); |
| 111 | InsertES3FormatCombo(&set, GL_R8_SNORM, GL_RED, GL_BYTE ); |
| 112 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_HALF_FLOAT ); |
| 113 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_HALF_FLOAT_OES ); |
| 114 | InsertES3FormatCombo(&set, GL_R32F, GL_RED, GL_FLOAT ); |
| 115 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_FLOAT ); |
| 116 | InsertES3FormatCombo(&set, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ); |
| 117 | InsertES3FormatCombo(&set, GL_R8I, GL_RED_INTEGER, GL_BYTE ); |
| 118 | InsertES3FormatCombo(&set, GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ); |
| 119 | InsertES3FormatCombo(&set, GL_R16I, GL_RED_INTEGER, GL_SHORT ); |
| 120 | InsertES3FormatCombo(&set, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ); |
| 121 | InsertES3FormatCombo(&set, GL_R32I, GL_RED_INTEGER, GL_INT ); |
| 122 | |
| 123 | // Unsized formats |
| 124 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 125 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ); |
| 126 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ); |
| 127 | InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ); |
| 128 | InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ); |
| 129 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ); |
| 130 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ); |
| 131 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ); |
| 132 | InsertES3FormatCombo(&set, GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ); |
| 133 | InsertES3FormatCombo(&set, GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE ); |
Jamie Madill | 689325c | 2015-07-20 14:36:53 -0400 | [diff] [blame] | 134 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_UNSIGNED_BYTE ); |
| 135 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_FLOAT ); |
| 136 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_HALF_FLOAT ); |
| 137 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_HALF_FLOAT_OES ); |
| 138 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_UNSIGNED_BYTE ); |
| 139 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_FLOAT ); |
| 140 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_HALF_FLOAT ); |
| 141 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_HALF_FLOAT_OES ); |
| 142 | InsertES3FormatCombo(&set, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 143 | |
| 144 | // Depth stencil formats |
| 145 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ); |
| 146 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); |
| 147 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); |
| 148 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ); |
| 149 | InsertES3FormatCombo(&set, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ); |
| 150 | InsertES3FormatCombo(&set, GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV); |
| 151 | |
| 152 | // From GL_EXT_sRGB |
| 153 | InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ); |
| 154 | InsertES3FormatCombo(&set, GL_SRGB8, GL_SRGB_EXT, GL_UNSIGNED_BYTE ); |
| 155 | |
| 156 | // From GL_OES_texture_float |
Jeff Muizelaar | bb1a5be | 2015-12-02 12:03:46 -0500 | [diff] [blame] | 157 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_FLOAT ); |
| 158 | InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_FLOAT ); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 159 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ); |
| 160 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ); |
| 161 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_FLOAT ); |
| 162 | |
| 163 | // From GL_OES_texture_half_float |
| 164 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ); |
| 165 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES ); |
| 166 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ); |
| 167 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES ); |
| 168 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ); |
| 169 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES ); |
| 170 | |
| 171 | // From GL_EXT_texture_format_BGRA8888 |
| 172 | InsertES3FormatCombo(&set, GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 173 | |
| 174 | // From GL_EXT_texture_storage |
| 175 | // | Internal format | Format | Type | |
| 176 | // | | | | |
| 177 | InsertES3FormatCombo(&set, GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ); |
| 178 | InsertES3FormatCombo(&set, GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ); |
| 179 | InsertES3FormatCombo(&set, GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ); |
| 180 | InsertES3FormatCombo(&set, GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ); |
| 181 | InsertES3FormatCombo(&set, GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ); |
| 182 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ); |
| 183 | InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ); |
| 184 | InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT_OES ); |
| 185 | InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ); |
| 186 | InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT_OES ); |
| 187 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ); |
| 188 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES ); |
| 189 | |
| 190 | // From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888 |
| 191 | InsertES3FormatCombo(&set, GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 192 | InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT); |
| 193 | InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 194 | InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT); |
| 195 | InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 196 | |
| 197 | // From GL_ANGLE_depth_texture |
| 198 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ); |
| 199 | |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 200 | // From GL_EXT_texture_norm16 |
| 201 | InsertES3FormatCombo(&set, GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT); |
| 202 | InsertES3FormatCombo(&set, GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT); |
| 203 | InsertES3FormatCombo(&set, GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT); |
| 204 | InsertES3FormatCombo(&set, GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT); |
| 205 | InsertES3FormatCombo(&set, GL_R16_SNORM_EXT, GL_RED, GL_SHORT); |
| 206 | InsertES3FormatCombo(&set, GL_RG16_SNORM_EXT, GL_RG, GL_SHORT); |
| 207 | InsertES3FormatCombo(&set, GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT); |
| 208 | InsertES3FormatCombo(&set, GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT); |
| 209 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 210 | return set; |
| 211 | } |
| 212 | |
| 213 | static bool ValidateTexImageFormatCombination(gl::Context *context, GLenum internalFormat, GLenum format, GLenum type) |
| 214 | { |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 215 | // For historical reasons, glTexImage2D and glTexImage3D pass in their internal format as a |
| 216 | // GLint instead of a GLenum. Therefor an invalid internal format gives a GL_INVALID_VALUE |
| 217 | // error instead of a GL_INVALID_ENUM error. As this validation function is only called in |
| 218 | // the validation codepaths for glTexImage2D/3D, we record a GL_INVALID_VALUE error. |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 219 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 220 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 221 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 222 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 223 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | // The type and format are valid if any supported internal format has that type and format |
| 227 | bool formatSupported = false; |
| 228 | bool typeSupported = false; |
| 229 | |
| 230 | static const ES3FormatCombinationSet es3FormatSet = BuildES3FormatSet(); |
| 231 | for (ES3FormatCombinationSet::const_iterator i = es3FormatSet.begin(); i != es3FormatSet.end(); i++) |
| 232 | { |
| 233 | if (i->format == format || i->type == type) |
| 234 | { |
| 235 | const gl::InternalFormat &info = gl::GetInternalFormatInfo(i->internalFormat); |
| 236 | bool supported = info.textureSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 237 | if (supported && i->type == type) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 238 | { |
| 239 | typeSupported = true; |
| 240 | } |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 241 | if (supported && i->format == format) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 242 | { |
| 243 | formatSupported = true; |
| 244 | } |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 245 | |
| 246 | // Early-out if both type and format are supported now |
| 247 | if (typeSupported && formatSupported) |
| 248 | { |
| 249 | break; |
| 250 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | if (!typeSupported || !formatSupported) |
| 255 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 256 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 257 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Check if this is a valid format combination to load texture data |
| 261 | ES3FormatCombination searchFormat; |
| 262 | searchFormat.internalFormat = internalFormat; |
| 263 | searchFormat.format = format; |
| 264 | searchFormat.type = type; |
| 265 | |
| 266 | if (es3FormatSet.find(searchFormat) == es3FormatSet.end()) |
| 267 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 268 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 269 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | return true; |
| 273 | } |
| 274 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 275 | bool ValidateES3TexImageParametersBase(Context *context, |
| 276 | GLenum target, |
| 277 | GLint level, |
| 278 | GLenum internalformat, |
| 279 | bool isCompressed, |
| 280 | bool isSubImage, |
| 281 | GLint xoffset, |
| 282 | GLint yoffset, |
| 283 | GLint zoffset, |
| 284 | GLsizei width, |
| 285 | GLsizei height, |
| 286 | GLsizei depth, |
| 287 | GLint border, |
| 288 | GLenum format, |
| 289 | GLenum type, |
| 290 | const GLvoid *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 291 | { |
| 292 | // Validate image size |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 293 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 294 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 295 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 296 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 299 | // Verify zero border |
| 300 | if (border != 0) |
| 301 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 302 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 303 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 304 | } |
| 305 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 306 | if (xoffset < 0 || yoffset < 0 || zoffset < 0 || |
| 307 | std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 308 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 309 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 310 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 311 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 312 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 315 | const gl::Caps &caps = context->getCaps(); |
| 316 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 317 | switch (target) |
| 318 | { |
| 319 | case GL_TEXTURE_2D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 320 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 321 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 322 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 323 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 324 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 325 | } |
| 326 | break; |
| 327 | |
| 328 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 329 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 330 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 331 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 332 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 333 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 334 | if (!isSubImage && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 335 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 336 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 337 | return false; |
| 338 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 339 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 340 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level)) |
| 341 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 342 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 343 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 344 | } |
| 345 | break; |
| 346 | |
| 347 | case GL_TEXTURE_3D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 348 | if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) || |
| 349 | static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) || |
| 350 | static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 351 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 352 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 353 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 354 | } |
| 355 | break; |
| 356 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 357 | case GL_TEXTURE_2D_ARRAY: |
| 358 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 359 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) || |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 360 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 361 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 362 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 363 | return false; |
| 364 | } |
| 365 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 366 | |
| 367 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 368 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 369 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 370 | } |
| 371 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 372 | gl::Texture *texture = context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 373 | if (!texture) |
| 374 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 375 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 376 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 377 | } |
| 378 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 379 | if (texture->getImmutableFormat() && !isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 380 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 381 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 382 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | // Validate texture formats |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 386 | GLenum actualInternalFormat = isSubImage ? texture->getInternalFormat(target, level) : internalformat; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 387 | const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 388 | if (isCompressed) |
| 389 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 390 | if (!actualFormatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 391 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 392 | context->handleError(Error( |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 393 | GL_INVALID_ENUM, "internalformat is not a supported compressed internal format.")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 394 | return false; |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 395 | } |
| 396 | |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 397 | if (!ValidCompressedImageSize(context, actualInternalFormat, width, height)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 398 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 399 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 400 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 403 | if (!actualFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 404 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 405 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 406 | return false; |
| 407 | } |
| 408 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 409 | if (target == GL_TEXTURE_3D) |
| 410 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 411 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 412 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | else |
| 416 | { |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 417 | if (!ValidateTexImageFormatCombination(context, actualInternalFormat, format, type)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 418 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 419 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL)) |
| 423 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 424 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 425 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | // Validate sub image parameters |
| 430 | if (isSubImage) |
| 431 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 432 | if (isCompressed != actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 433 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 434 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 435 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 438 | if (width == 0 || height == 0 || depth == 0) |
| 439 | { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 444 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 445 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 446 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 450 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 451 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 452 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 453 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 454 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 457 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 458 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 459 | static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 460 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 461 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 462 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 466 | // Check for pixel unpack buffer related API errors |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 467 | gl::Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 468 | if (pixelUnpackBuffer != NULL) |
| 469 | { |
| 470 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 471 | // would exceed the data store size. |
| 472 | size_t widthSize = static_cast<size_t>(width); |
| 473 | size_t heightSize = static_cast<size_t>(height); |
| 474 | size_t depthSize = static_cast<size_t>(depth); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 475 | GLenum sizedFormat = GetSizedInternalFormat(actualInternalFormat, type); |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 476 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 477 | size_t pixelBytes = static_cast<size_t>(gl::GetInternalFormatInfo(sizedFormat).pixelBytes); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 478 | |
| 479 | if (!rx::IsUnsignedMultiplicationSafe(widthSize, heightSize) || |
| 480 | !rx::IsUnsignedMultiplicationSafe(widthSize * heightSize, depthSize) || |
| 481 | !rx::IsUnsignedMultiplicationSafe(widthSize * heightSize * depthSize, pixelBytes)) |
| 482 | { |
| 483 | // Overflow past the end of the buffer |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 484 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 485 | return false; |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 486 | } |
| 487 | |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 488 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat); |
| 489 | size_t copyBytes = formatInfo.computeBlockSize(type, width, height); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 490 | size_t offset = reinterpret_cast<size_t>(pixels); |
| 491 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 492 | if (!rx::IsUnsignedAdditionSafe(offset, copyBytes) || |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 493 | ((offset + copyBytes) > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 494 | { |
| 495 | // Overflow past the end of the buffer |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 496 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 497 | return false; |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | // ...data is not evenly divisible into the number of bytes needed to store in memory a datum |
| 501 | // indicated by type. |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 502 | if (!isCompressed) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 503 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 504 | size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes); |
| 505 | |
| 506 | if ((offset % dataBytesPerPixel) != 0) |
| 507 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 508 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 509 | return false; |
| 510 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 511 | } |
| 512 | |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 513 | // ...the buffer object's data store is currently mapped. |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 514 | if (pixelUnpackBuffer->isMapped()) |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 515 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 516 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 517 | return false; |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 518 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 521 | return true; |
| 522 | } |
| 523 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 524 | bool ValidateES3TexImage2DParameters(Context *context, |
| 525 | GLenum target, |
| 526 | GLint level, |
| 527 | GLenum internalformat, |
| 528 | bool isCompressed, |
| 529 | bool isSubImage, |
| 530 | GLint xoffset, |
| 531 | GLint yoffset, |
| 532 | GLint zoffset, |
| 533 | GLsizei width, |
| 534 | GLsizei height, |
| 535 | GLsizei depth, |
| 536 | GLint border, |
| 537 | GLenum format, |
| 538 | GLenum type, |
| 539 | const GLvoid *pixels) |
| 540 | { |
| 541 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 542 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 543 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 544 | return false; |
| 545 | } |
| 546 | |
| 547 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 548 | isSubImage, xoffset, yoffset, zoffset, width, height, |
| 549 | depth, border, format, type, pixels); |
| 550 | } |
| 551 | |
| 552 | bool ValidateES3TexImage3DParameters(Context *context, |
| 553 | GLenum target, |
| 554 | GLint level, |
| 555 | GLenum internalformat, |
| 556 | bool isCompressed, |
| 557 | bool isSubImage, |
| 558 | GLint xoffset, |
| 559 | GLint yoffset, |
| 560 | GLint zoffset, |
| 561 | GLsizei width, |
| 562 | GLsizei height, |
| 563 | GLsizei depth, |
| 564 | GLint border, |
| 565 | GLenum format, |
| 566 | GLenum type, |
| 567 | const GLvoid *pixels) |
| 568 | { |
| 569 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 570 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 571 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 572 | return false; |
| 573 | } |
| 574 | |
| 575 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 576 | isSubImage, xoffset, yoffset, zoffset, width, height, |
| 577 | depth, border, format, type, pixels); |
| 578 | } |
| 579 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 580 | struct EffectiveInternalFormatInfo |
| 581 | { |
| 582 | GLenum mEffectiveFormat; |
| 583 | GLenum mDestFormat; |
| 584 | GLuint mMinRedBits; |
| 585 | GLuint mMaxRedBits; |
| 586 | GLuint mMinGreenBits; |
| 587 | GLuint mMaxGreenBits; |
| 588 | GLuint mMinBlueBits; |
| 589 | GLuint mMaxBlueBits; |
| 590 | GLuint mMinAlphaBits; |
| 591 | GLuint mMaxAlphaBits; |
| 592 | |
| 593 | EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits, |
| 594 | GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits, |
| 595 | GLuint minAlphaBits, GLuint maxAlphaBits) |
| 596 | : mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits), |
| 597 | mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits), |
| 598 | mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits), |
| 599 | mMaxAlphaBits(maxAlphaBits) {}; |
| 600 | }; |
| 601 | |
| 602 | typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList; |
| 603 | |
| 604 | static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList() |
| 605 | { |
| 606 | EffectiveInternalFormatList list; |
| 607 | |
| 608 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 609 | // linear source buffer component sizes. |
| 610 | // | Source channel min/max sizes | |
| 611 | // Effective Internal Format | N/A | R | G | B | A | |
| 612 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8)); |
| 613 | list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0)); |
| 614 | list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0)); |
| 615 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0)); |
| 616 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0)); |
| 617 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 618 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 619 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8)); |
| 620 | list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2)); |
| 621 | |
| 622 | return list; |
| 623 | } |
| 624 | |
| 625 | static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList() |
| 626 | { |
| 627 | EffectiveInternalFormatList list; |
| 628 | |
| 629 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 630 | // linear source buffer component sizes. |
| 631 | // | Source channel min/max sizes | |
| 632 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 633 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 634 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX)); |
| 635 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 636 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX)); |
| 637 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX)); |
| 638 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 639 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 640 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8)); |
| 641 | |
| 642 | return list; |
| 643 | } |
| 644 | |
| 645 | static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, const InternalFormat &destFormat, |
| 646 | GLenum *outEffectiveFormat) |
| 647 | { |
| 648 | const EffectiveInternalFormatList *list = NULL; |
| 649 | GLenum targetFormat = GL_NONE; |
| 650 | |
| 651 | if (destFormat.pixelBytes > 0) |
| 652 | { |
| 653 | static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList(); |
| 654 | list = &sizedList; |
| 655 | } |
| 656 | else |
| 657 | { |
| 658 | static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList(); |
| 659 | list = &unsizedList; |
| 660 | targetFormat = destFormat.format; |
| 661 | } |
| 662 | |
| 663 | for (size_t curFormat = 0; curFormat < list->size(); ++curFormat) |
| 664 | { |
| 665 | const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat); |
| 666 | if ((formatInfo.mDestFormat == targetFormat) && |
| 667 | (formatInfo.mMinRedBits <= srcFormat.redBits && formatInfo.mMaxRedBits >= srcFormat.redBits) && |
| 668 | (formatInfo.mMinGreenBits <= srcFormat.greenBits && formatInfo.mMaxGreenBits >= srcFormat.greenBits) && |
| 669 | (formatInfo.mMinBlueBits <= srcFormat.blueBits && formatInfo.mMaxBlueBits >= srcFormat.blueBits) && |
| 670 | (formatInfo.mMinAlphaBits <= srcFormat.alphaBits && formatInfo.mMaxAlphaBits >= srcFormat.alphaBits)) |
| 671 | { |
| 672 | *outEffectiveFormat = formatInfo.mEffectiveFormat; |
| 673 | return true; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | return false; |
| 678 | } |
| 679 | |
| 680 | struct CopyConversion |
| 681 | { |
| 682 | GLenum mTextureFormat; |
| 683 | GLenum mFramebufferFormat; |
| 684 | |
| 685 | CopyConversion(GLenum textureFormat, GLenum framebufferFormat) |
| 686 | : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { } |
| 687 | |
| 688 | bool operator<(const CopyConversion& other) const |
| 689 | { |
| 690 | return memcmp(this, &other, sizeof(CopyConversion)) < 0; |
| 691 | } |
| 692 | }; |
| 693 | |
| 694 | typedef std::set<CopyConversion> CopyConversionSet; |
| 695 | |
| 696 | static CopyConversionSet BuildValidES3CopyTexImageCombinations() |
| 697 | { |
| 698 | CopyConversionSet set; |
| 699 | |
| 700 | // From ES 3.0.1 spec, table 3.15 |
| 701 | set.insert(CopyConversion(GL_ALPHA, GL_RGBA)); |
| 702 | set.insert(CopyConversion(GL_LUMINANCE, GL_RED)); |
| 703 | set.insert(CopyConversion(GL_LUMINANCE, GL_RG)); |
| 704 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGB)); |
| 705 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA)); |
| 706 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA)); |
| 707 | set.insert(CopyConversion(GL_RED, GL_RED)); |
| 708 | set.insert(CopyConversion(GL_RED, GL_RG)); |
| 709 | set.insert(CopyConversion(GL_RED, GL_RGB)); |
| 710 | set.insert(CopyConversion(GL_RED, GL_RGBA)); |
| 711 | set.insert(CopyConversion(GL_RG, GL_RG)); |
| 712 | set.insert(CopyConversion(GL_RG, GL_RGB)); |
| 713 | set.insert(CopyConversion(GL_RG, GL_RGBA)); |
| 714 | set.insert(CopyConversion(GL_RGB, GL_RGB)); |
| 715 | set.insert(CopyConversion(GL_RGB, GL_RGBA)); |
| 716 | set.insert(CopyConversion(GL_RGBA, GL_RGBA)); |
| 717 | |
| 718 | // Necessary for ANGLE back-buffers |
| 719 | set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT)); |
| 720 | set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT)); |
| 721 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT)); |
| 722 | set.insert(CopyConversion(GL_RED, GL_BGRA_EXT)); |
| 723 | set.insert(CopyConversion(GL_RG, GL_BGRA_EXT)); |
| 724 | set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT)); |
| 725 | set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT)); |
| 726 | |
| 727 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER)); |
| 728 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER)); |
| 729 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER)); |
| 730 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER)); |
| 731 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER)); |
| 732 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER)); |
| 733 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER)); |
| 734 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER)); |
| 735 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER)); |
| 736 | set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER)); |
| 737 | |
| 738 | return set; |
| 739 | } |
| 740 | |
Corentin Wallez | 7628768 | 2016-04-25 09:23:38 -0400 | [diff] [blame] | 741 | static bool EqualOrFirstZero(GLuint first, GLuint second) |
| 742 | { |
| 743 | return first == 0 || first == second; |
| 744 | } |
| 745 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 746 | static bool IsValidES3CopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle) |
| 747 | { |
| 748 | const InternalFormat &textureInternalFormatInfo = GetInternalFormatInfo(textureInternalFormat); |
| 749 | const InternalFormat &framebufferInternalFormatInfo = GetInternalFormatInfo(frameBufferInternalFormat); |
| 750 | |
| 751 | static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations(); |
| 752 | if (conversionSet.find(CopyConversion(textureInternalFormatInfo.format, framebufferInternalFormatInfo.format)) != conversionSet.end()) |
| 753 | { |
| 754 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 755 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 756 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 757 | // conversion between fixed and floating point. |
| 758 | |
| 759 | if ((textureInternalFormatInfo.colorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.colorEncoding == GL_SRGB)) |
| 760 | { |
| 761 | return false; |
| 762 | } |
| 763 | |
| 764 | if (((textureInternalFormatInfo.componentType == GL_INT) != (framebufferInternalFormatInfo.componentType == GL_INT )) || |
| 765 | ((textureInternalFormatInfo.componentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.componentType == GL_UNSIGNED_INT))) |
| 766 | { |
| 767 | return false; |
| 768 | } |
| 769 | |
| 770 | if ((textureInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 771 | textureInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 772 | textureInternalFormatInfo.componentType == GL_FLOAT) && |
| 773 | !(framebufferInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 774 | framebufferInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 775 | framebufferInternalFormatInfo.componentType == GL_FLOAT)) |
| 776 | { |
| 777 | return false; |
| 778 | } |
| 779 | |
| 780 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 781 | // The effective internal format of the source buffer is determined with the following rules applied in order: |
| 782 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the |
| 783 | // effective internal format is the source buffer's sized internal format. |
| 784 | // * If the source buffer is a texture that was created with an unsized base internal format, then the |
| 785 | // effective internal format is the source image array's effective internal format, as specified by table |
| 786 | // 3.12, which is determined from the <format> and <type> that were used when the source image array was |
| 787 | // specified by TexImage*. |
| 788 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where |
| 789 | // Destination Internal Format matches internalformat and where the [source channel sizes] are consistent |
| 790 | // with the values of the source buffer's [channel sizes]. Table 3.17 is used if the |
| 791 | // FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING |
| 792 | // is SRGB. |
| 793 | const InternalFormat *sourceEffectiveFormat = NULL; |
| 794 | if (readBufferHandle != 0) |
| 795 | { |
| 796 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer |
| 797 | if (framebufferInternalFormatInfo.pixelBytes > 0) |
| 798 | { |
| 799 | sourceEffectiveFormat = &framebufferInternalFormatInfo; |
| 800 | } |
| 801 | else |
| 802 | { |
| 803 | // Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format |
| 804 | // texture. We can use the same table we use when creating textures to get its effective sized format. |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 805 | GLenum sizedInternalFormat = GetSizedInternalFormat(framebufferInternalFormatInfo.format, framebufferInternalFormatInfo.type); |
| 806 | sourceEffectiveFormat = &GetInternalFormatInfo(sizedInternalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | else |
| 810 | { |
| 811 | // The effective internal format must be derived from the source framebuffer's channel sizes. |
| 812 | // This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 813 | if (framebufferInternalFormatInfo.colorEncoding == GL_LINEAR) |
| 814 | { |
| 815 | GLenum effectiveFormat; |
| 816 | if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, &effectiveFormat)) |
| 817 | { |
| 818 | sourceEffectiveFormat = &GetInternalFormatInfo(effectiveFormat); |
| 819 | } |
| 820 | else |
| 821 | { |
| 822 | return false; |
| 823 | } |
| 824 | } |
| 825 | else if (framebufferInternalFormatInfo.colorEncoding == GL_SRGB) |
| 826 | { |
| 827 | // SRGB buffers can only be copied to sized format destinations according to table 3.18 |
| 828 | if ((textureInternalFormatInfo.pixelBytes > 0) && |
| 829 | (framebufferInternalFormatInfo.redBits >= 1 && framebufferInternalFormatInfo.redBits <= 8) && |
| 830 | (framebufferInternalFormatInfo.greenBits >= 1 && framebufferInternalFormatInfo.greenBits <= 8) && |
| 831 | (framebufferInternalFormatInfo.blueBits >= 1 && framebufferInternalFormatInfo.blueBits <= 8) && |
| 832 | (framebufferInternalFormatInfo.alphaBits >= 1 && framebufferInternalFormatInfo.alphaBits <= 8)) |
| 833 | { |
| 834 | sourceEffectiveFormat = &GetInternalFormatInfo(GL_SRGB8_ALPHA8); |
| 835 | } |
| 836 | else |
| 837 | { |
| 838 | return false; |
| 839 | } |
| 840 | } |
| 841 | else |
| 842 | { |
| 843 | UNREACHABLE(); |
| 844 | return false; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | if (textureInternalFormatInfo.pixelBytes > 0) |
| 849 | { |
Corentin Wallez | 7628768 | 2016-04-25 09:23:38 -0400 | [diff] [blame] | 850 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination |
| 851 | // format is sized, component sizes of the source and destination formats must exactly |
| 852 | // match if the destination format exists. |
| 853 | if (!EqualOrFirstZero(textureInternalFormatInfo.redBits, |
| 854 | sourceEffectiveFormat->redBits) || |
| 855 | !EqualOrFirstZero(textureInternalFormatInfo.greenBits, |
| 856 | sourceEffectiveFormat->greenBits) || |
| 857 | !EqualOrFirstZero(textureInternalFormatInfo.blueBits, |
| 858 | sourceEffectiveFormat->blueBits) || |
| 859 | !EqualOrFirstZero(textureInternalFormatInfo.alphaBits, |
| 860 | sourceEffectiveFormat->alphaBits)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 861 | { |
| 862 | return false; |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | |
| 867 | return true; // A conversion function exists, and no rule in the specification has precluded conversion |
| 868 | // between these formats. |
| 869 | } |
| 870 | |
| 871 | return false; |
| 872 | } |
| 873 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 874 | bool ValidateES3CopyTexImageParametersBase(ValidationContext *context, |
| 875 | GLenum target, |
| 876 | GLint level, |
| 877 | GLenum internalformat, |
| 878 | bool isSubImage, |
| 879 | GLint xoffset, |
| 880 | GLint yoffset, |
| 881 | GLint zoffset, |
| 882 | GLint x, |
| 883 | GLint y, |
| 884 | GLsizei width, |
| 885 | GLsizei height, |
| 886 | GLint border) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 887 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 888 | GLenum textureInternalFormat; |
| 889 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 890 | xoffset, yoffset, zoffset, x, y, width, height, |
| 891 | border, &textureInternalFormat)) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 892 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 893 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 894 | } |
| 895 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 896 | const auto &state = context->getState(); |
| 897 | const gl::Framebuffer *framebuffer = state.getReadFramebuffer(); |
| 898 | GLuint readFramebufferID = framebuffer->id(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 899 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 900 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 901 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 902 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 903 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 904 | } |
| 905 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 906 | if (readFramebufferID != 0 && framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 907 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 908 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 909 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 910 | } |
| 911 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 912 | const gl::FramebufferAttachment *source = framebuffer->getReadColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 913 | GLenum colorbufferInternalFormat = source->getInternalFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 914 | |
| 915 | if (isSubImage) |
| 916 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 917 | if (!IsValidES3CopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 918 | readFramebufferID)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 919 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 920 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 921 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 922 | } |
| 923 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 924 | else |
| 925 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 926 | if (!gl::IsValidES3CopyTexImageCombination(internalformat, colorbufferInternalFormat, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 927 | readFramebufferID)) |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 928 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 929 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 930 | return false; |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 934 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 935 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 936 | } |
| 937 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 938 | bool ValidateES3CopyTexImage2DParameters(ValidationContext *context, |
| 939 | GLenum target, |
| 940 | GLint level, |
| 941 | GLenum internalformat, |
| 942 | bool isSubImage, |
| 943 | GLint xoffset, |
| 944 | GLint yoffset, |
| 945 | GLint zoffset, |
| 946 | GLint x, |
| 947 | GLint y, |
| 948 | GLsizei width, |
| 949 | GLsizei height, |
| 950 | GLint border) |
| 951 | { |
| 952 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 953 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 954 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 955 | return false; |
| 956 | } |
| 957 | |
| 958 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 959 | xoffset, yoffset, zoffset, x, y, width, height, |
| 960 | border); |
| 961 | } |
| 962 | |
| 963 | bool ValidateES3CopyTexImage3DParameters(ValidationContext *context, |
| 964 | GLenum target, |
| 965 | GLint level, |
| 966 | GLenum internalformat, |
| 967 | bool isSubImage, |
| 968 | GLint xoffset, |
| 969 | GLint yoffset, |
| 970 | GLint zoffset, |
| 971 | GLint x, |
| 972 | GLint y, |
| 973 | GLsizei width, |
| 974 | GLsizei height, |
| 975 | GLint border) |
| 976 | { |
| 977 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 978 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 979 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 980 | return false; |
| 981 | } |
| 982 | |
| 983 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 984 | xoffset, yoffset, zoffset, x, y, width, height, |
| 985 | border); |
| 986 | } |
| 987 | |
| 988 | bool ValidateES3TexStorageParametersBase(Context *context, |
| 989 | GLenum target, |
| 990 | GLsizei levels, |
| 991 | GLenum internalformat, |
| 992 | GLsizei width, |
| 993 | GLsizei height, |
| 994 | GLsizei depth) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 995 | { |
| 996 | if (width < 1 || height < 1 || depth < 1 || levels < 1) |
| 997 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 998 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 999 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 1002 | GLsizei maxDim = std::max(width, height); |
| 1003 | if (target != GL_TEXTURE_2D_ARRAY) |
| 1004 | { |
| 1005 | maxDim = std::max(maxDim, depth); |
| 1006 | } |
| 1007 | |
| 1008 | if (levels > gl::log2(maxDim) + 1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1009 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1010 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1011 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1012 | } |
| 1013 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1014 | const gl::Caps &caps = context->getCaps(); |
| 1015 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1016 | switch (target) |
| 1017 | { |
| 1018 | case GL_TEXTURE_2D: |
| 1019 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1020 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1021 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1022 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1023 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1024 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | break; |
| 1028 | |
Geoff Lang | 01c21d2 | 2013-09-24 11:52:16 -0400 | [diff] [blame] | 1029 | case GL_TEXTURE_CUBE_MAP: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1030 | { |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1031 | if (width != height) |
| 1032 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1033 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1034 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1037 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1038 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1039 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1040 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | break; |
| 1044 | |
| 1045 | case GL_TEXTURE_3D: |
| 1046 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1047 | if (static_cast<GLuint>(width) > caps.max3DTextureSize || |
| 1048 | static_cast<GLuint>(height) > caps.max3DTextureSize || |
| 1049 | static_cast<GLuint>(depth) > caps.max3DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1050 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1051 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1052 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | break; |
| 1056 | |
| 1057 | case GL_TEXTURE_2D_ARRAY: |
| 1058 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1059 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1060 | static_cast<GLuint>(height) > caps.max2DTextureSize || |
| 1061 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1062 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1063 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1064 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | break; |
| 1068 | |
| 1069 | default: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1070 | UNREACHABLE(); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1071 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1072 | } |
| 1073 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1074 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1075 | if (!texture || texture->id() == 0) |
| 1076 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1077 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1078 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1081 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1082 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1083 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1084 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1085 | } |
| 1086 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1087 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1088 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1089 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1090 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1091 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1092 | } |
| 1093 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1094 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1095 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1096 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1097 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | return true; |
| 1101 | } |
| 1102 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1103 | bool ValidateES3TexStorage2DParameters(Context *context, |
| 1104 | GLenum target, |
| 1105 | GLsizei levels, |
| 1106 | GLenum internalformat, |
| 1107 | GLsizei width, |
| 1108 | GLsizei height, |
| 1109 | GLsizei depth) |
| 1110 | { |
| 1111 | if (!ValidTexture2DTarget(context, target)) |
| 1112 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1113 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1114 | return false; |
| 1115 | } |
| 1116 | |
| 1117 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 1118 | height, depth); |
| 1119 | } |
| 1120 | |
| 1121 | bool ValidateES3TexStorage3DParameters(Context *context, |
| 1122 | GLenum target, |
| 1123 | GLsizei levels, |
| 1124 | GLenum internalformat, |
| 1125 | GLsizei width, |
| 1126 | GLsizei height, |
| 1127 | GLsizei depth) |
| 1128 | { |
| 1129 | if (!ValidTexture3DTarget(context, target)) |
| 1130 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1131 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1132 | return false; |
| 1133 | } |
| 1134 | |
| 1135 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 1136 | height, depth); |
| 1137 | } |
| 1138 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1139 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 1140 | { |
| 1141 | if (context->getClientVersion() < 3) |
| 1142 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1143 | context->handleError(Error(GL_INVALID_OPERATION, "GLES version < 3.0")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1144 | return false; |
| 1145 | } |
| 1146 | |
| 1147 | return ValidateBeginQueryBase(context, target, id); |
| 1148 | } |
| 1149 | |
| 1150 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 1151 | { |
| 1152 | if (context->getClientVersion() < 3) |
| 1153 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1154 | context->handleError(Error(GL_INVALID_OPERATION, "GLES version < 3.0")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1155 | return false; |
| 1156 | } |
| 1157 | |
| 1158 | return ValidateEndQueryBase(context, target); |
| 1159 | } |
| 1160 | |
| 1161 | bool ValidateGetQueryiv(Context *context, GLenum target, GLenum pname, GLint *params) |
| 1162 | { |
| 1163 | if (context->getClientVersion() < 3) |
| 1164 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1165 | context->handleError(Error(GL_INVALID_OPERATION, "GLES version < 3.0")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1166 | return false; |
| 1167 | } |
| 1168 | |
| 1169 | return ValidateGetQueryivBase(context, target, pname); |
| 1170 | } |
| 1171 | |
| 1172 | bool ValidateGetQueryObjectuiv(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1173 | { |
| 1174 | if (context->getClientVersion() < 3) |
| 1175 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1176 | context->handleError(Error(GL_INVALID_OPERATION, "GLES version < 3.0")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1177 | return false; |
| 1178 | } |
| 1179 | |
| 1180 | return ValidateGetQueryObjectValueBase(context, id, pname); |
| 1181 | } |
| 1182 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1183 | bool ValidateFramebufferTextureLayer(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1184 | GLuint texture, GLint level, GLint layer) |
| 1185 | { |
| 1186 | if (context->getClientVersion() < 3) |
| 1187 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1188 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1189 | return false; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1190 | } |
| 1191 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1192 | if (layer < 0) |
| 1193 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1194 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1195 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 1199 | { |
| 1200 | return false; |
| 1201 | } |
| 1202 | |
| 1203 | const gl::Caps &caps = context->getCaps(); |
| 1204 | if (texture != 0) |
| 1205 | { |
| 1206 | gl::Texture *tex = context->getTexture(texture); |
| 1207 | ASSERT(tex); |
| 1208 | |
| 1209 | switch (tex->getTarget()) |
| 1210 | { |
| 1211 | case GL_TEXTURE_2D_ARRAY: |
| 1212 | { |
| 1213 | if (level > gl::log2(caps.max2DTextureSize)) |
| 1214 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1215 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1216 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 1220 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1221 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1222 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1223 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1224 | } |
| 1225 | break; |
| 1226 | |
| 1227 | case GL_TEXTURE_3D: |
| 1228 | { |
| 1229 | if (level > gl::log2(caps.max3DTextureSize)) |
| 1230 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1231 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1232 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | if (static_cast<GLuint>(layer) >= caps.max3DTextureSize) |
| 1236 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1237 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1238 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1239 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1240 | } |
| 1241 | break; |
| 1242 | |
| 1243 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1244 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1245 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1246 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1247 | |
| 1248 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(tex->getTarget(), level)); |
| 1249 | if (internalFormatInfo.compressed) |
| 1250 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1251 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1252 | return false; |
| 1253 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | return true; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1257 | } |
| 1258 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1259 | bool ValidES3ReadFormatType(Context *context, GLenum internalFormat, GLenum format, GLenum type) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1260 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1261 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 1262 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1263 | switch (format) |
| 1264 | { |
| 1265 | case GL_RGBA: |
| 1266 | switch (type) |
| 1267 | { |
| 1268 | case GL_UNSIGNED_BYTE: |
| 1269 | break; |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 1270 | case GL_UNSIGNED_SHORT: |
| 1271 | if (internalFormatInfo.componentType != GL_UNSIGNED_NORMALIZED && |
| 1272 | internalFormatInfo.type != GL_UNSIGNED_SHORT) |
| 1273 | { |
| 1274 | return false; |
| 1275 | } |
| 1276 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1277 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 1278 | if (internalFormat != GL_RGB10_A2) |
| 1279 | { |
| 1280 | return false; |
| 1281 | } |
| 1282 | break; |
Geoff Lang | 1ec57f8 | 2013-10-16 11:43:23 -0400 | [diff] [blame] | 1283 | case GL_FLOAT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1284 | if (internalFormatInfo.componentType != GL_FLOAT) |
Geoff Lang | 1ec57f8 | 2013-10-16 11:43:23 -0400 | [diff] [blame] | 1285 | { |
| 1286 | return false; |
| 1287 | } |
| 1288 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1289 | default: |
| 1290 | return false; |
| 1291 | } |
| 1292 | break; |
| 1293 | case GL_RGBA_INTEGER: |
| 1294 | switch (type) |
| 1295 | { |
| 1296 | case GL_INT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1297 | if (internalFormatInfo.componentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1298 | { |
| 1299 | return false; |
| 1300 | } |
| 1301 | break; |
| 1302 | case GL_UNSIGNED_INT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1303 | if (internalFormatInfo.componentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1304 | { |
| 1305 | return false; |
| 1306 | } |
| 1307 | break; |
| 1308 | default: |
| 1309 | return false; |
| 1310 | } |
| 1311 | break; |
| 1312 | case GL_BGRA_EXT: |
| 1313 | switch (type) |
| 1314 | { |
| 1315 | case GL_UNSIGNED_BYTE: |
| 1316 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 1317 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 1318 | break; |
| 1319 | default: |
| 1320 | return false; |
| 1321 | } |
| 1322 | break; |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1323 | case GL_RG_EXT: |
| 1324 | case GL_RED_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1325 | if (!context->getExtensions().textureRG) |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1326 | { |
| 1327 | return false; |
| 1328 | } |
| 1329 | switch (type) |
| 1330 | { |
| 1331 | case GL_UNSIGNED_BYTE: |
| 1332 | break; |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 1333 | case GL_UNSIGNED_SHORT: |
| 1334 | if (internalFormatInfo.componentType != GL_UNSIGNED_NORMALIZED && |
| 1335 | internalFormatInfo.type != GL_UNSIGNED_SHORT) |
| 1336 | { |
| 1337 | return false; |
| 1338 | } |
| 1339 | break; |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1340 | default: |
| 1341 | return false; |
| 1342 | } |
| 1343 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1344 | default: |
| 1345 | return false; |
| 1346 | } |
| 1347 | return true; |
| 1348 | } |
| 1349 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1350 | bool ValidateES3RenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples, |
| 1351 | GLenum internalformat, GLsizei width, GLsizei height) |
| 1352 | { |
| 1353 | if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, height)) |
| 1354 | { |
| 1355 | return false; |
| 1356 | } |
| 1357 | |
| 1358 | //The ES3 spec(section 4.4.2) states that the internal format must be sized and not an integer format if samples is greater than zero. |
| 1359 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1360 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0) |
| 1361 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1362 | context->handleError(Error(GL_INVALID_OPERATION)); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1363 | return false; |
| 1364 | } |
| 1365 | |
| 1366 | // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY. |
| 1367 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 1368 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 1369 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1370 | context->handleError( |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 1371 | Error(GL_INVALID_OPERATION, |
| 1372 | "Samples must not be greater than maximum supported value for the format.")); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1373 | return false; |
| 1374 | } |
| 1375 | |
| 1376 | return true; |
| 1377 | } |
| 1378 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1379 | bool ValidateInvalidateFramebuffer(Context *context, GLenum target, GLsizei numAttachments, |
| 1380 | const GLenum *attachments) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1381 | { |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1382 | if (context->getClientVersion() < 3) |
| 1383 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1384 | context->handleError( |
| 1385 | Error(GL_INVALID_OPERATION, "Operation only supported on ES 3.0 and above")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1386 | return false; |
| 1387 | } |
| 1388 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1389 | bool defaultFramebuffer = false; |
| 1390 | |
| 1391 | switch (target) |
| 1392 | { |
| 1393 | case GL_DRAW_FRAMEBUFFER: |
| 1394 | case GL_FRAMEBUFFER: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1395 | defaultFramebuffer = context->getState().getDrawFramebuffer()->id() == 0; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1396 | break; |
| 1397 | case GL_READ_FRAMEBUFFER: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1398 | defaultFramebuffer = context->getState().getReadFramebuffer()->id() == 0; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1399 | break; |
| 1400 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1401 | context->handleError(Error(GL_INVALID_ENUM, "Invalid framebuffer target")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1402 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1403 | } |
| 1404 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1405 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, defaultFramebuffer); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1406 | } |
| 1407 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1408 | bool ValidateClearBuffer(ValidationContext *context) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1409 | { |
| 1410 | if (context->getClientVersion() < 3) |
| 1411 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1412 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1413 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1414 | } |
| 1415 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1416 | const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1417 | if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1418 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1419 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1420 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | return true; |
| 1424 | } |
| 1425 | |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1426 | bool ValidateDrawRangeElements(Context *context, |
| 1427 | GLenum mode, |
| 1428 | GLuint start, |
| 1429 | GLuint end, |
| 1430 | GLsizei count, |
| 1431 | GLenum type, |
| 1432 | const GLvoid *indices, |
| 1433 | IndexRange *indexRange) |
| 1434 | { |
| 1435 | if (context->getClientVersion() < 3) |
| 1436 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1437 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1438 | return false; |
| 1439 | } |
| 1440 | |
| 1441 | if (end < start) |
| 1442 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1443 | context->handleError(Error(GL_INVALID_VALUE, "end < start")); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1444 | return false; |
| 1445 | } |
| 1446 | |
| 1447 | if (!ValidateDrawElements(context, mode, count, type, indices, 0, indexRange)) |
| 1448 | { |
| 1449 | return false; |
| 1450 | } |
| 1451 | |
| 1452 | if (indexRange->end > end || indexRange->start < start) |
| 1453 | { |
| 1454 | // GL spec says that behavior in this case is undefined - generating an error is fine. |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1455 | context->handleError( |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1456 | Error(GL_INVALID_OPERATION, "Indices are out of the start, end range.")); |
| 1457 | return false; |
| 1458 | } |
| 1459 | return true; |
| 1460 | } |
| 1461 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1462 | bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1463 | { |
| 1464 | if (context->getClientVersion() < 3) |
| 1465 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1466 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1467 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1470 | return ValidateGetUniformBase(context, program, location); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1471 | } |
| 1472 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1473 | bool ValidateReadBuffer(Context *context, GLenum src) |
| 1474 | { |
| 1475 | if (context->getClientVersion() < 3) |
| 1476 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1477 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1478 | return false; |
| 1479 | } |
| 1480 | |
| 1481 | Framebuffer *readFBO = context->getState().getReadFramebuffer(); |
| 1482 | |
| 1483 | if (readFBO == nullptr) |
| 1484 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1485 | context->handleError(gl::Error(GL_INVALID_OPERATION, "No active read framebuffer.")); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1486 | return false; |
| 1487 | } |
| 1488 | |
| 1489 | if (src == GL_NONE) |
| 1490 | { |
| 1491 | return true; |
| 1492 | } |
| 1493 | |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 1494 | if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1495 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1496 | context->handleError(gl::Error(GL_INVALID_ENUM, "Unknown enum for 'src' in ReadBuffer")); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1497 | return false; |
| 1498 | } |
| 1499 | |
| 1500 | if (readFBO->id() == 0) |
| 1501 | { |
| 1502 | if (src != GL_BACK) |
| 1503 | { |
| 1504 | const char *errorMsg = "'src' must be GL_NONE or GL_BACK when reading from the default framebuffer."; |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1505 | context->handleError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1506 | return false; |
| 1507 | } |
| 1508 | } |
| 1509 | else |
| 1510 | { |
| 1511 | GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0); |
| 1512 | |
| 1513 | if (drawBuffer >= context->getCaps().maxDrawBuffers) |
| 1514 | { |
| 1515 | const char *errorMsg = "'src' is greater than MAX_DRAW_BUFFERS."; |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1516 | context->handleError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1517 | return false; |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | return true; |
| 1522 | } |
| 1523 | |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1524 | bool ValidateCompressedTexImage3D(Context *context, |
| 1525 | GLenum target, |
| 1526 | GLint level, |
| 1527 | GLenum internalformat, |
| 1528 | GLsizei width, |
| 1529 | GLsizei height, |
| 1530 | GLsizei depth, |
| 1531 | GLint border, |
| 1532 | GLsizei imageSize, |
| 1533 | const GLvoid *data) |
| 1534 | { |
| 1535 | if (context->getClientVersion() < 3) |
| 1536 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1537 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1538 | return false; |
| 1539 | } |
| 1540 | |
| 1541 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
| 1542 | if (imageSize < 0 || |
| 1543 | static_cast<GLuint>(imageSize) != |
| 1544 | formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height)) |
| 1545 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1546 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1547 | return false; |
| 1548 | } |
| 1549 | |
| 1550 | // 3D texture target validation |
| 1551 | if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) |
| 1552 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1553 | context->handleError( |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1554 | Error(GL_INVALID_ENUM, "Must specify a valid 3D texture destination target")); |
| 1555 | return false; |
| 1556 | } |
| 1557 | |
| 1558 | // validateES3TexImageFormat sets the error code if there is an error |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1559 | if (!ValidateES3TexImage3DParameters(context, target, level, internalformat, true, false, 0, 0, |
| 1560 | 0, width, height, depth, border, GL_NONE, GL_NONE, data)) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1561 | { |
| 1562 | return false; |
| 1563 | } |
| 1564 | |
| 1565 | return true; |
| 1566 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1567 | |
| 1568 | bool ValidateBindVertexArray(Context *context, GLuint array) |
| 1569 | { |
| 1570 | if (context->getClientVersion() < 3) |
| 1571 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1572 | context->handleError(Error(GL_INVALID_OPERATION)); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1573 | return false; |
| 1574 | } |
| 1575 | |
| 1576 | return ValidateBindVertexArrayBase(context, array); |
| 1577 | } |
| 1578 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1579 | bool ValidateIsVertexArray(Context *context) |
| 1580 | { |
| 1581 | if (context->getClientVersion() < 3) |
| 1582 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1583 | context->handleError(Error(GL_INVALID_OPERATION)); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1584 | return false; |
| 1585 | } |
| 1586 | |
| 1587 | return true; |
| 1588 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1589 | |
| 1590 | bool ValidateProgramBinary(Context *context, |
| 1591 | GLuint program, |
| 1592 | GLenum binaryFormat, |
| 1593 | const void *binary, |
| 1594 | GLint length) |
| 1595 | { |
| 1596 | if (context->getClientVersion() < 3) |
| 1597 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1598 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1599 | return false; |
| 1600 | } |
| 1601 | |
| 1602 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1603 | } |
| 1604 | |
| 1605 | bool ValidateGetProgramBinary(Context *context, |
| 1606 | GLuint program, |
| 1607 | GLsizei bufSize, |
| 1608 | GLsizei *length, |
| 1609 | GLenum *binaryFormat, |
| 1610 | void *binary) |
| 1611 | { |
| 1612 | if (context->getClientVersion() < 3) |
| 1613 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1614 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1615 | return false; |
| 1616 | } |
| 1617 | |
| 1618 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1619 | } |
| 1620 | |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1621 | bool ValidateProgramParameteri(Context *context, GLuint program, GLenum pname, GLint value) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1622 | { |
| 1623 | if (context->getClientVersion() < 3) |
| 1624 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1625 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1626 | return false; |
| 1627 | } |
| 1628 | |
| 1629 | if (GetValidProgram(context, program) == nullptr) |
| 1630 | { |
| 1631 | return false; |
| 1632 | } |
| 1633 | |
| 1634 | switch (pname) |
| 1635 | { |
| 1636 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1637 | if (value != GL_FALSE && value != GL_TRUE) |
| 1638 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1639 | context->handleError(Error( |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1640 | GL_INVALID_VALUE, "Invalid value, expected GL_FALSE or GL_TRUE: %i", value)); |
| 1641 | return false; |
| 1642 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1643 | break; |
| 1644 | |
| 1645 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1646 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname: 0x%X", pname)); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1647 | return false; |
| 1648 | } |
| 1649 | |
| 1650 | return true; |
| 1651 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1652 | |
| 1653 | bool ValidateBlitFramebuffer(Context *context, |
| 1654 | GLint srcX0, |
| 1655 | GLint srcY0, |
| 1656 | GLint srcX1, |
| 1657 | GLint srcY1, |
| 1658 | GLint dstX0, |
| 1659 | GLint dstY0, |
| 1660 | GLint dstX1, |
| 1661 | GLint dstY1, |
| 1662 | GLbitfield mask, |
| 1663 | GLenum filter) |
| 1664 | { |
| 1665 | if (context->getClientVersion() < 3) |
| 1666 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1667 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1668 | return false; |
| 1669 | } |
| 1670 | |
| 1671 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 1672 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1673 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1674 | |
| 1675 | bool ValidateClearBufferiv(ValidationContext *context, |
| 1676 | GLenum buffer, |
| 1677 | GLint drawbuffer, |
| 1678 | const GLint *value) |
| 1679 | { |
| 1680 | switch (buffer) |
| 1681 | { |
| 1682 | case GL_COLOR: |
| 1683 | if (drawbuffer < 0 || |
| 1684 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1685 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1686 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1687 | return false; |
| 1688 | } |
| 1689 | break; |
| 1690 | |
| 1691 | case GL_STENCIL: |
| 1692 | if (drawbuffer != 0) |
| 1693 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1694 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1695 | return false; |
| 1696 | } |
| 1697 | break; |
| 1698 | |
| 1699 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1700 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1701 | return false; |
| 1702 | } |
| 1703 | |
| 1704 | return ValidateClearBuffer(context); |
| 1705 | } |
| 1706 | |
| 1707 | bool ValidateClearBufferuiv(ValidationContext *context, |
| 1708 | GLenum buffer, |
| 1709 | GLint drawbuffer, |
| 1710 | const GLuint *value) |
| 1711 | { |
| 1712 | switch (buffer) |
| 1713 | { |
| 1714 | case GL_COLOR: |
| 1715 | if (drawbuffer < 0 || |
| 1716 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1717 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1718 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1719 | return false; |
| 1720 | } |
| 1721 | break; |
| 1722 | |
| 1723 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1724 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1725 | return false; |
| 1726 | } |
| 1727 | |
| 1728 | return ValidateClearBuffer(context); |
| 1729 | } |
| 1730 | |
| 1731 | bool ValidateClearBufferfv(ValidationContext *context, |
| 1732 | GLenum buffer, |
| 1733 | GLint drawbuffer, |
| 1734 | const GLfloat *value) |
| 1735 | { |
| 1736 | switch (buffer) |
| 1737 | { |
| 1738 | case GL_COLOR: |
| 1739 | if (drawbuffer < 0 || |
| 1740 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1741 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1742 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1743 | return false; |
| 1744 | } |
| 1745 | break; |
| 1746 | |
| 1747 | case GL_DEPTH: |
| 1748 | if (drawbuffer != 0) |
| 1749 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1750 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1751 | return false; |
| 1752 | } |
| 1753 | break; |
| 1754 | |
| 1755 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1756 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1757 | return false; |
| 1758 | } |
| 1759 | |
| 1760 | return ValidateClearBuffer(context); |
| 1761 | } |
| 1762 | |
| 1763 | bool ValidateClearBufferfi(ValidationContext *context, |
| 1764 | GLenum buffer, |
| 1765 | GLint drawbuffer, |
| 1766 | GLfloat depth, |
| 1767 | GLint stencil) |
| 1768 | { |
| 1769 | switch (buffer) |
| 1770 | { |
| 1771 | case GL_DEPTH_STENCIL: |
| 1772 | if (drawbuffer != 0) |
| 1773 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1774 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1775 | return false; |
| 1776 | } |
| 1777 | break; |
| 1778 | |
| 1779 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1780 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1781 | return false; |
| 1782 | } |
| 1783 | |
| 1784 | return ValidateClearBuffer(context); |
| 1785 | } |
| 1786 | |
| 1787 | bool ValidateDrawBuffers(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 1788 | { |
| 1789 | if (context->getClientVersion() < 3) |
| 1790 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1791 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1792 | return false; |
| 1793 | } |
| 1794 | |
| 1795 | return ValidateDrawBuffersBase(context, n, bufs); |
| 1796 | } |
| 1797 | |
| 1798 | bool ValidateCopyTexSubImage3D(Context *context, |
| 1799 | GLenum target, |
| 1800 | GLint level, |
| 1801 | GLint xoffset, |
| 1802 | GLint yoffset, |
| 1803 | GLint zoffset, |
| 1804 | GLint x, |
| 1805 | GLint y, |
| 1806 | GLsizei width, |
| 1807 | GLsizei height) |
| 1808 | { |
| 1809 | if (context->getClientVersion() < 3) |
| 1810 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1811 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1812 | return false; |
| 1813 | } |
| 1814 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1815 | return ValidateES3CopyTexImage3DParameters(context, target, level, GL_NONE, true, xoffset, |
| 1816 | yoffset, zoffset, x, y, width, height, 0); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1817 | } |
| 1818 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1819 | bool ValidateTexImage3D(Context *context, |
| 1820 | GLenum target, |
| 1821 | GLint level, |
| 1822 | GLint internalformat, |
| 1823 | GLsizei width, |
| 1824 | GLsizei height, |
| 1825 | GLsizei depth, |
| 1826 | GLint border, |
| 1827 | GLenum format, |
| 1828 | GLenum type, |
| 1829 | const GLvoid *pixels) |
| 1830 | { |
| 1831 | if (context->getClientVersion() < 3) |
| 1832 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1833 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1834 | return false; |
| 1835 | } |
| 1836 | |
| 1837 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
| 1838 | 0, 0, width, height, depth, border, format, type, |
| 1839 | pixels); |
| 1840 | } |
| 1841 | |
| 1842 | bool ValidateTexSubImage3D(Context *context, |
| 1843 | GLenum target, |
| 1844 | GLint level, |
| 1845 | GLint xoffset, |
| 1846 | GLint yoffset, |
| 1847 | GLint zoffset, |
| 1848 | GLsizei width, |
| 1849 | GLsizei height, |
| 1850 | GLsizei depth, |
| 1851 | GLenum format, |
| 1852 | GLenum type, |
| 1853 | const GLvoid *pixels) |
| 1854 | { |
| 1855 | if (context->getClientVersion() < 3) |
| 1856 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1857 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1858 | return false; |
| 1859 | } |
| 1860 | |
| 1861 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1862 | yoffset, zoffset, width, height, depth, 0, format, type, |
| 1863 | pixels); |
| 1864 | } |
| 1865 | |
| 1866 | bool ValidateCompressedTexSubImage3D(Context *context, |
| 1867 | GLenum target, |
| 1868 | GLint level, |
| 1869 | GLint xoffset, |
| 1870 | GLint yoffset, |
| 1871 | GLint zoffset, |
| 1872 | GLsizei width, |
| 1873 | GLsizei height, |
| 1874 | GLsizei depth, |
| 1875 | GLenum format, |
| 1876 | GLsizei imageSize, |
| 1877 | const GLvoid *data) |
| 1878 | { |
| 1879 | if (context->getClientVersion() < 3) |
| 1880 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1881 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1882 | return false; |
| 1883 | } |
| 1884 | |
| 1885 | const InternalFormat &formatInfo = GetInternalFormatInfo(format); |
| 1886 | if (imageSize < 0 || |
| 1887 | static_cast<GLuint>(imageSize) != |
| 1888 | formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height)) |
| 1889 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1890 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1891 | return false; |
| 1892 | } |
| 1893 | |
| 1894 | if (!data) |
| 1895 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1896 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1897 | return false; |
| 1898 | } |
| 1899 | |
| 1900 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, true, true, 0, 0, 0, |
| 1901 | width, height, depth, 0, GL_NONE, GL_NONE, data); |
| 1902 | } |
| 1903 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1904 | bool ValidateGenQueries(Context *context, GLint n, GLuint *) |
| 1905 | { |
| 1906 | return ValidateGenOrDeleteES3(context, n); |
| 1907 | } |
| 1908 | |
| 1909 | bool ValidateDeleteQueries(Context *context, GLint n, const GLuint *) |
| 1910 | { |
| 1911 | return ValidateGenOrDeleteES3(context, n); |
| 1912 | } |
| 1913 | |
| 1914 | bool ValidateGenSamplers(Context *context, GLint count, GLuint *) |
| 1915 | { |
| 1916 | return ValidateGenOrDeleteCountES3(context, count); |
| 1917 | } |
| 1918 | |
| 1919 | bool ValidateDeleteSamplers(Context *context, GLint count, const GLuint *) |
| 1920 | { |
| 1921 | return ValidateGenOrDeleteCountES3(context, count); |
| 1922 | } |
| 1923 | |
| 1924 | bool ValidateGenTransformFeedbacks(Context *context, GLint n, GLuint *) |
| 1925 | { |
| 1926 | return ValidateGenOrDeleteES3(context, n); |
| 1927 | } |
| 1928 | |
| 1929 | bool ValidateDeleteTransformFeedbacks(Context *context, GLint n, const GLuint *ids) |
| 1930 | { |
| 1931 | if (!ValidateGenOrDeleteES3(context, n)) |
| 1932 | { |
| 1933 | return false; |
| 1934 | } |
| 1935 | for (GLint i = 0; i < n; ++i) |
| 1936 | { |
| 1937 | auto *transformFeedback = context->getTransformFeedback(ids[i]); |
| 1938 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 1939 | { |
| 1940 | // ES 3.0.4 section 2.15.1 page 86 |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1941 | context->handleError( |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1942 | Error(GL_INVALID_OPERATION, "Attempt to delete active transform feedback.")); |
| 1943 | return false; |
| 1944 | } |
| 1945 | } |
| 1946 | return true; |
| 1947 | } |
| 1948 | |
| 1949 | bool ValidateGenVertexArrays(Context *context, GLint n, GLuint *) |
| 1950 | { |
| 1951 | return ValidateGenOrDeleteES3(context, n); |
| 1952 | } |
| 1953 | |
| 1954 | bool ValidateDeleteVertexArrays(Context *context, GLint n, const GLuint *) |
| 1955 | { |
| 1956 | return ValidateGenOrDeleteES3(context, n); |
| 1957 | } |
| 1958 | |
| 1959 | bool ValidateGenOrDeleteES3(Context *context, GLint n) |
| 1960 | { |
| 1961 | if (context->getClientVersion() < 3) |
| 1962 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1963 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1964 | return false; |
| 1965 | } |
| 1966 | return ValidateGenOrDelete(context, n); |
| 1967 | } |
| 1968 | |
| 1969 | bool ValidateGenOrDeleteCountES3(Context *context, GLint count) |
| 1970 | { |
| 1971 | if (context->getClientVersion() < 3) |
| 1972 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1973 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1974 | return false; |
| 1975 | } |
| 1976 | if (count < 0) |
| 1977 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1978 | context->handleError(Error(GL_INVALID_VALUE, "count < 0")); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1979 | return false; |
| 1980 | } |
| 1981 | return true; |
| 1982 | } |
| 1983 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1984 | bool ValidateBeginTransformFeedback(Context *context, GLenum primitiveMode) |
| 1985 | { |
| 1986 | if (context->getClientVersion() < 3) |
| 1987 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1988 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1989 | return false; |
| 1990 | } |
| 1991 | switch (primitiveMode) |
| 1992 | { |
| 1993 | case GL_TRIANGLES: |
| 1994 | case GL_LINES: |
| 1995 | case GL_POINTS: |
| 1996 | break; |
| 1997 | |
| 1998 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1999 | context->handleError(Error(GL_INVALID_ENUM, "Invalid primitive mode.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2000 | return false; |
| 2001 | } |
| 2002 | |
| 2003 | TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
| 2004 | ASSERT(transformFeedback != nullptr); |
| 2005 | |
| 2006 | if (transformFeedback->isActive()) |
| 2007 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2008 | context->handleError(Error(GL_INVALID_OPERATION, "Transform feedback is already active.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
| 2011 | return true; |
| 2012 | } |
| 2013 | |
Olli Etuaho | 3747791 | 2016-03-30 14:54:40 +0300 | [diff] [blame] | 2014 | bool ValidateSamplerParameteri(Context *context, GLuint sampler, GLenum pname, GLint param) |
| 2015 | { |
| 2016 | if (context->getClientVersion() < 3) |
| 2017 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2018 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 3747791 | 2016-03-30 14:54:40 +0300 | [diff] [blame] | 2019 | return false; |
| 2020 | } |
| 2021 | |
| 2022 | if (!context->isSampler(sampler)) |
| 2023 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2024 | context->handleError(Error(GL_INVALID_OPERATION)); |
Olli Etuaho | 3747791 | 2016-03-30 14:54:40 +0300 | [diff] [blame] | 2025 | return false; |
| 2026 | } |
| 2027 | |
| 2028 | if (!ValidateSamplerObjectParameter(context, pname)) |
| 2029 | { |
| 2030 | return false; |
| 2031 | } |
| 2032 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 2033 | if (!ValidateTexParamParameters(context, GL_TEXTURE_2D, pname, param)) |
Olli Etuaho | 3747791 | 2016-03-30 14:54:40 +0300 | [diff] [blame] | 2034 | { |
| 2035 | return false; |
| 2036 | } |
| 2037 | return true; |
| 2038 | } |
| 2039 | |
| 2040 | bool ValidateSamplerParameterf(Context *context, GLuint sampler, GLenum pname, GLfloat param) |
| 2041 | { |
| 2042 | // The only float parameters are MIN_LOD and MAX_LOD. For these any value is permissible, so |
| 2043 | // ValidateSamplerParameteri can be used for validation here. |
| 2044 | return ValidateSamplerParameteri(context, sampler, pname, static_cast<GLint>(param)); |
| 2045 | } |
| 2046 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2047 | bool ValidateGetBufferPointerv(Context *context, GLenum target, GLenum pname, GLvoid **params) |
| 2048 | { |
| 2049 | if (context->getClientVersion() < 3) |
| 2050 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2051 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2052 | return false; |
| 2053 | } |
| 2054 | |
| 2055 | return ValidateGetBufferPointervBase(context, target, pname, params); |
| 2056 | } |
| 2057 | |
| 2058 | bool ValidateUnmapBuffer(Context *context, GLenum target) |
| 2059 | { |
| 2060 | if (context->getClientVersion() < 3) |
| 2061 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2062 | context->handleError(Error(GL_INVALID_OPERATION)); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2063 | return false; |
| 2064 | } |
| 2065 | |
| 2066 | return ValidateUnmapBufferBase(context, target); |
| 2067 | } |
| 2068 | |
| 2069 | bool ValidateMapBufferRange(Context *context, |
| 2070 | GLenum target, |
| 2071 | GLintptr offset, |
| 2072 | GLsizeiptr length, |
| 2073 | GLbitfield access) |
| 2074 | { |
| 2075 | if (context->getClientVersion() < 3) |
| 2076 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2077 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2078 | return false; |
| 2079 | } |
| 2080 | |
| 2081 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 2082 | } |
| 2083 | |
| 2084 | bool ValidateFlushMappedBufferRange(Context *context, |
| 2085 | GLenum target, |
| 2086 | GLintptr offset, |
| 2087 | GLsizeiptr length) |
| 2088 | { |
| 2089 | if (context->getClientVersion() < 3) |
| 2090 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2091 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2092 | return false; |
| 2093 | } |
| 2094 | |
| 2095 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 2096 | } |
| 2097 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2098 | } // namespace gl |