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 ); |
| 134 | |
| 135 | // Depth stencil formats |
| 136 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ); |
| 137 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); |
| 138 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); |
| 139 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ); |
| 140 | InsertES3FormatCombo(&set, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ); |
| 141 | InsertES3FormatCombo(&set, GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV); |
| 142 | |
| 143 | // From GL_EXT_sRGB |
| 144 | InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ); |
| 145 | InsertES3FormatCombo(&set, GL_SRGB8, GL_SRGB_EXT, GL_UNSIGNED_BYTE ); |
| 146 | |
| 147 | // From GL_OES_texture_float |
| 148 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ); |
| 149 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ); |
| 150 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_FLOAT ); |
| 151 | |
| 152 | // From GL_OES_texture_half_float |
| 153 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ); |
| 154 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES ); |
| 155 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ); |
| 156 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES ); |
| 157 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ); |
| 158 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES ); |
| 159 | |
| 160 | // From GL_EXT_texture_format_BGRA8888 |
| 161 | InsertES3FormatCombo(&set, GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 162 | |
| 163 | // From GL_EXT_texture_storage |
| 164 | // | Internal format | Format | Type | |
| 165 | // | | | | |
| 166 | InsertES3FormatCombo(&set, GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ); |
| 167 | InsertES3FormatCombo(&set, GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ); |
| 168 | InsertES3FormatCombo(&set, GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ); |
| 169 | InsertES3FormatCombo(&set, GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ); |
| 170 | InsertES3FormatCombo(&set, GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ); |
| 171 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ); |
| 172 | InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ); |
| 173 | InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT_OES ); |
| 174 | InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ); |
| 175 | InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT_OES ); |
| 176 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ); |
| 177 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES ); |
| 178 | |
| 179 | // From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888 |
| 180 | InsertES3FormatCombo(&set, GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 181 | InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT); |
| 182 | InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 183 | InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT); |
| 184 | InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 185 | |
| 186 | // From GL_ANGLE_depth_texture |
| 187 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ); |
| 188 | |
| 189 | // Compressed formats |
| 190 | // From ES 3.0.1 spec, table 3.16 |
| 191 | // | Internal format | Format | Type | |
| 192 | // | | | | |
| 193 | InsertES3FormatCombo(&set, GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE); |
| 194 | InsertES3FormatCombo(&set, GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE); |
| 195 | InsertES3FormatCombo(&set, GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE); |
| 196 | InsertES3FormatCombo(&set, GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE); |
| 197 | InsertES3FormatCombo(&set, GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE); |
| 198 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE); |
| 199 | InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE); |
| 200 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE); |
| 201 | InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE); |
| 202 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE); |
| 203 | InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE); |
| 204 | |
| 205 | |
| 206 | // From GL_EXT_texture_compression_dxt1 |
| 207 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE); |
| 208 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE); |
| 209 | |
| 210 | // From GL_ANGLE_texture_compression_dxt3 |
| 211 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE); |
| 212 | |
| 213 | // From GL_ANGLE_texture_compression_dxt5 |
| 214 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE); |
| 215 | |
| 216 | return set; |
| 217 | } |
| 218 | |
| 219 | static bool ValidateTexImageFormatCombination(gl::Context *context, GLenum internalFormat, GLenum format, GLenum type) |
| 220 | { |
| 221 | // Note: dEQP 2013.4 expects an INVALID_VALUE error for TexImage3D with an invalid |
| 222 | // internal format. (dEQP-GLES3.functional.negative_api.texture.teximage3d) |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 223 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 224 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 225 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 226 | context->recordError(Error(GL_INVALID_ENUM)); |
| 227 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // The type and format are valid if any supported internal format has that type and format |
| 231 | bool formatSupported = false; |
| 232 | bool typeSupported = false; |
| 233 | |
| 234 | static const ES3FormatCombinationSet es3FormatSet = BuildES3FormatSet(); |
| 235 | for (ES3FormatCombinationSet::const_iterator i = es3FormatSet.begin(); i != es3FormatSet.end(); i++) |
| 236 | { |
| 237 | if (i->format == format || i->type == type) |
| 238 | { |
| 239 | const gl::InternalFormat &info = gl::GetInternalFormatInfo(i->internalFormat); |
| 240 | bool supported = info.textureSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 241 | if (supported && i->type == type) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 242 | { |
| 243 | typeSupported = true; |
| 244 | } |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 245 | if (supported && i->format == format) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 246 | { |
| 247 | formatSupported = true; |
| 248 | } |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 249 | |
| 250 | // Early-out if both type and format are supported now |
| 251 | if (typeSupported && formatSupported) |
| 252 | { |
| 253 | break; |
| 254 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | if (!typeSupported || !formatSupported) |
| 259 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 260 | context->recordError(Error(GL_INVALID_ENUM)); |
| 261 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | // Check if this is a valid format combination to load texture data |
| 265 | ES3FormatCombination searchFormat; |
| 266 | searchFormat.internalFormat = internalFormat; |
| 267 | searchFormat.format = format; |
| 268 | searchFormat.type = type; |
| 269 | |
| 270 | if (es3FormatSet.find(searchFormat) == es3FormatSet.end()) |
| 271 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 272 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 273 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | return true; |
| 277 | } |
| 278 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 279 | bool ValidateES3TexImageParameters(Context *context, GLenum target, GLint level, GLenum internalformat, bool isCompressed, bool isSubImage, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 280 | GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 281 | GLint border, GLenum format, GLenum type, const GLvoid *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 282 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 283 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 284 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 285 | context->recordError(Error(GL_INVALID_ENUM)); |
| 286 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 287 | } |
| 288 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 289 | // Validate image size |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 290 | if (!ValidImageSize(context, target, level, width, height, depth)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 291 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 292 | context->recordError(Error(GL_INVALID_VALUE)); |
| 293 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 296 | // Verify zero border |
| 297 | if (border != 0) |
| 298 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 299 | context->recordError(Error(GL_INVALID_VALUE)); |
| 300 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 301 | } |
| 302 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 303 | if (xoffset < 0 || yoffset < 0 || zoffset < 0 || |
| 304 | std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 305 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 306 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 307 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 308 | context->recordError(Error(GL_INVALID_VALUE)); |
| 309 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 312 | const gl::Caps &caps = context->getCaps(); |
| 313 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 314 | switch (target) |
| 315 | { |
| 316 | case GL_TEXTURE_2D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 317 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 318 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 319 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 320 | context->recordError(Error(GL_INVALID_VALUE)); |
| 321 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 322 | } |
| 323 | break; |
| 324 | |
| 325 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 326 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 327 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 328 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 329 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 330 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 331 | if (!isSubImage && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 332 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 333 | context->recordError(Error(GL_INVALID_VALUE)); |
| 334 | return false; |
| 335 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 336 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 337 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level)) |
| 338 | { |
| 339 | context->recordError(Error(GL_INVALID_VALUE)); |
| 340 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 341 | } |
| 342 | break; |
| 343 | |
| 344 | case GL_TEXTURE_3D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 345 | if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) || |
| 346 | static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) || |
| 347 | static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 348 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 349 | context->recordError(Error(GL_INVALID_VALUE)); |
| 350 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 351 | } |
| 352 | break; |
| 353 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 354 | case GL_TEXTURE_2D_ARRAY: |
| 355 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 356 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) || |
| 357 | static_cast<GLuint>(depth) > (caps.maxArrayTextureLayers >> level)) |
| 358 | { |
| 359 | context->recordError(Error(GL_INVALID_VALUE)); |
| 360 | return false; |
| 361 | } |
| 362 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 363 | |
| 364 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 365 | context->recordError(Error(GL_INVALID_ENUM)); |
| 366 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 367 | } |
| 368 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 369 | gl::Texture *texture = context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 370 | if (!texture) |
| 371 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 372 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 373 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | if (texture->isImmutable() && !isSubImage) |
| 377 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 378 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 379 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // Validate texture formats |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 383 | GLenum actualInternalFormat = isSubImage ? texture->getInternalFormat(target, level) : internalformat; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 384 | const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 385 | if (isCompressed) |
| 386 | { |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 387 | if (!ValidCompressedImageSize(context, actualInternalFormat, width, height)) |
| 388 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 389 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 390 | return false; |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 391 | } |
| 392 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 393 | if (!actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 394 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 395 | context->recordError(Error(GL_INVALID_ENUM)); |
| 396 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | if (target == GL_TEXTURE_3D) |
| 400 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 401 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 402 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | else |
| 406 | { |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 407 | if (!ValidateTexImageFormatCombination(context, actualInternalFormat, format, type)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 408 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 409 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL)) |
| 413 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 414 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 415 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | // Validate sub image parameters |
| 420 | if (isSubImage) |
| 421 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 422 | if (isCompressed != actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 423 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 424 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 425 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 426 | } |
| 427 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 428 | if (width == 0 || height == 0 || depth == 0) |
| 429 | { |
| 430 | return false; |
| 431 | } |
| 432 | |
| 433 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 434 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 435 | context->recordError(Error(GL_INVALID_VALUE)); |
| 436 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 440 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 441 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 442 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 443 | context->recordError(Error(GL_INVALID_VALUE)); |
| 444 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 445 | } |
| 446 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 447 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 448 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 449 | static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 450 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 451 | context->recordError(Error(GL_INVALID_VALUE)); |
| 452 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 456 | // Check for pixel unpack buffer related API errors |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 457 | gl::Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 458 | if (pixelUnpackBuffer != NULL) |
| 459 | { |
| 460 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 461 | // would exceed the data store size. |
| 462 | size_t widthSize = static_cast<size_t>(width); |
| 463 | size_t heightSize = static_cast<size_t>(height); |
| 464 | size_t depthSize = static_cast<size_t>(depth); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 465 | GLenum sizedFormat = GetSizedInternalFormat(actualInternalFormat, type); |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 466 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 467 | size_t pixelBytes = static_cast<size_t>(gl::GetInternalFormatInfo(sizedFormat).pixelBytes); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 468 | |
| 469 | if (!rx::IsUnsignedMultiplicationSafe(widthSize, heightSize) || |
| 470 | !rx::IsUnsignedMultiplicationSafe(widthSize * heightSize, depthSize) || |
| 471 | !rx::IsUnsignedMultiplicationSafe(widthSize * heightSize * depthSize, pixelBytes)) |
| 472 | { |
| 473 | // Overflow past the end of the buffer |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 474 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 475 | return false; |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 476 | } |
| 477 | |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 478 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat); |
| 479 | size_t copyBytes = formatInfo.computeBlockSize(type, width, height); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 480 | size_t offset = reinterpret_cast<size_t>(pixels); |
| 481 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 482 | if (!rx::IsUnsignedAdditionSafe(offset, copyBytes) || |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 483 | ((offset + copyBytes) > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 484 | { |
| 485 | // Overflow past the end of the buffer |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 486 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 487 | return false; |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | // ...data is not evenly divisible into the number of bytes needed to store in memory a datum |
| 491 | // indicated by type. |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 492 | if (!isCompressed) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 493 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 494 | size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes); |
| 495 | |
| 496 | if ((offset % dataBytesPerPixel) != 0) |
| 497 | { |
| 498 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 499 | return false; |
| 500 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 501 | } |
| 502 | |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 503 | // ...the buffer object's data store is currently mapped. |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 504 | if (pixelUnpackBuffer->isMapped()) |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 505 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 506 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 507 | return false; |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 508 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 511 | return true; |
| 512 | } |
| 513 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 514 | struct EffectiveInternalFormatInfo |
| 515 | { |
| 516 | GLenum mEffectiveFormat; |
| 517 | GLenum mDestFormat; |
| 518 | GLuint mMinRedBits; |
| 519 | GLuint mMaxRedBits; |
| 520 | GLuint mMinGreenBits; |
| 521 | GLuint mMaxGreenBits; |
| 522 | GLuint mMinBlueBits; |
| 523 | GLuint mMaxBlueBits; |
| 524 | GLuint mMinAlphaBits; |
| 525 | GLuint mMaxAlphaBits; |
| 526 | |
| 527 | EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits, |
| 528 | GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits, |
| 529 | GLuint minAlphaBits, GLuint maxAlphaBits) |
| 530 | : mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits), |
| 531 | mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits), |
| 532 | mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits), |
| 533 | mMaxAlphaBits(maxAlphaBits) {}; |
| 534 | }; |
| 535 | |
| 536 | typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList; |
| 537 | |
| 538 | static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList() |
| 539 | { |
| 540 | EffectiveInternalFormatList list; |
| 541 | |
| 542 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 543 | // linear source buffer component sizes. |
| 544 | // | Source channel min/max sizes | |
| 545 | // Effective Internal Format | N/A | R | G | B | A | |
| 546 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8)); |
| 547 | list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0)); |
| 548 | list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0)); |
| 549 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0)); |
| 550 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0)); |
| 551 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 552 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 553 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8)); |
| 554 | list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2)); |
| 555 | |
| 556 | return list; |
| 557 | } |
| 558 | |
| 559 | static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList() |
| 560 | { |
| 561 | EffectiveInternalFormatList list; |
| 562 | |
| 563 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 564 | // linear source buffer component sizes. |
| 565 | // | Source channel min/max sizes | |
| 566 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 567 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 568 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX)); |
| 569 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 570 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX)); |
| 571 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX)); |
| 572 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 573 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 574 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8)); |
| 575 | |
| 576 | return list; |
| 577 | } |
| 578 | |
| 579 | static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, const InternalFormat &destFormat, |
| 580 | GLenum *outEffectiveFormat) |
| 581 | { |
| 582 | const EffectiveInternalFormatList *list = NULL; |
| 583 | GLenum targetFormat = GL_NONE; |
| 584 | |
| 585 | if (destFormat.pixelBytes > 0) |
| 586 | { |
| 587 | static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList(); |
| 588 | list = &sizedList; |
| 589 | } |
| 590 | else |
| 591 | { |
| 592 | static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList(); |
| 593 | list = &unsizedList; |
| 594 | targetFormat = destFormat.format; |
| 595 | } |
| 596 | |
| 597 | for (size_t curFormat = 0; curFormat < list->size(); ++curFormat) |
| 598 | { |
| 599 | const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat); |
| 600 | if ((formatInfo.mDestFormat == targetFormat) && |
| 601 | (formatInfo.mMinRedBits <= srcFormat.redBits && formatInfo.mMaxRedBits >= srcFormat.redBits) && |
| 602 | (formatInfo.mMinGreenBits <= srcFormat.greenBits && formatInfo.mMaxGreenBits >= srcFormat.greenBits) && |
| 603 | (formatInfo.mMinBlueBits <= srcFormat.blueBits && formatInfo.mMaxBlueBits >= srcFormat.blueBits) && |
| 604 | (formatInfo.mMinAlphaBits <= srcFormat.alphaBits && formatInfo.mMaxAlphaBits >= srcFormat.alphaBits)) |
| 605 | { |
| 606 | *outEffectiveFormat = formatInfo.mEffectiveFormat; |
| 607 | return true; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | return false; |
| 612 | } |
| 613 | |
| 614 | struct CopyConversion |
| 615 | { |
| 616 | GLenum mTextureFormat; |
| 617 | GLenum mFramebufferFormat; |
| 618 | |
| 619 | CopyConversion(GLenum textureFormat, GLenum framebufferFormat) |
| 620 | : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { } |
| 621 | |
| 622 | bool operator<(const CopyConversion& other) const |
| 623 | { |
| 624 | return memcmp(this, &other, sizeof(CopyConversion)) < 0; |
| 625 | } |
| 626 | }; |
| 627 | |
| 628 | typedef std::set<CopyConversion> CopyConversionSet; |
| 629 | |
| 630 | static CopyConversionSet BuildValidES3CopyTexImageCombinations() |
| 631 | { |
| 632 | CopyConversionSet set; |
| 633 | |
| 634 | // From ES 3.0.1 spec, table 3.15 |
| 635 | set.insert(CopyConversion(GL_ALPHA, GL_RGBA)); |
| 636 | set.insert(CopyConversion(GL_LUMINANCE, GL_RED)); |
| 637 | set.insert(CopyConversion(GL_LUMINANCE, GL_RG)); |
| 638 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGB)); |
| 639 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA)); |
| 640 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA)); |
| 641 | set.insert(CopyConversion(GL_RED, GL_RED)); |
| 642 | set.insert(CopyConversion(GL_RED, GL_RG)); |
| 643 | set.insert(CopyConversion(GL_RED, GL_RGB)); |
| 644 | set.insert(CopyConversion(GL_RED, GL_RGBA)); |
| 645 | set.insert(CopyConversion(GL_RG, GL_RG)); |
| 646 | set.insert(CopyConversion(GL_RG, GL_RGB)); |
| 647 | set.insert(CopyConversion(GL_RG, GL_RGBA)); |
| 648 | set.insert(CopyConversion(GL_RGB, GL_RGB)); |
| 649 | set.insert(CopyConversion(GL_RGB, GL_RGBA)); |
| 650 | set.insert(CopyConversion(GL_RGBA, GL_RGBA)); |
| 651 | |
| 652 | // Necessary for ANGLE back-buffers |
| 653 | set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT)); |
| 654 | set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT)); |
| 655 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT)); |
| 656 | set.insert(CopyConversion(GL_RED, GL_BGRA_EXT)); |
| 657 | set.insert(CopyConversion(GL_RG, GL_BGRA_EXT)); |
| 658 | set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT)); |
| 659 | set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT)); |
| 660 | |
| 661 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER)); |
| 662 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER)); |
| 663 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER)); |
| 664 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER)); |
| 665 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER)); |
| 666 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER)); |
| 667 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER)); |
| 668 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER)); |
| 669 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER)); |
| 670 | set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER)); |
| 671 | |
| 672 | return set; |
| 673 | } |
| 674 | |
| 675 | static bool IsValidES3CopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle) |
| 676 | { |
| 677 | const InternalFormat &textureInternalFormatInfo = GetInternalFormatInfo(textureInternalFormat); |
| 678 | const InternalFormat &framebufferInternalFormatInfo = GetInternalFormatInfo(frameBufferInternalFormat); |
| 679 | |
| 680 | static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations(); |
| 681 | if (conversionSet.find(CopyConversion(textureInternalFormatInfo.format, framebufferInternalFormatInfo.format)) != conversionSet.end()) |
| 682 | { |
| 683 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 684 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 685 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 686 | // conversion between fixed and floating point. |
| 687 | |
| 688 | if ((textureInternalFormatInfo.colorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.colorEncoding == GL_SRGB)) |
| 689 | { |
| 690 | return false; |
| 691 | } |
| 692 | |
| 693 | if (((textureInternalFormatInfo.componentType == GL_INT) != (framebufferInternalFormatInfo.componentType == GL_INT )) || |
| 694 | ((textureInternalFormatInfo.componentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.componentType == GL_UNSIGNED_INT))) |
| 695 | { |
| 696 | return false; |
| 697 | } |
| 698 | |
| 699 | if ((textureInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 700 | textureInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 701 | textureInternalFormatInfo.componentType == GL_FLOAT) && |
| 702 | !(framebufferInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 703 | framebufferInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 704 | framebufferInternalFormatInfo.componentType == GL_FLOAT)) |
| 705 | { |
| 706 | return false; |
| 707 | } |
| 708 | |
| 709 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 710 | // The effective internal format of the source buffer is determined with the following rules applied in order: |
| 711 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the |
| 712 | // effective internal format is the source buffer's sized internal format. |
| 713 | // * If the source buffer is a texture that was created with an unsized base internal format, then the |
| 714 | // effective internal format is the source image array's effective internal format, as specified by table |
| 715 | // 3.12, which is determined from the <format> and <type> that were used when the source image array was |
| 716 | // specified by TexImage*. |
| 717 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where |
| 718 | // Destination Internal Format matches internalformat and where the [source channel sizes] are consistent |
| 719 | // with the values of the source buffer's [channel sizes]. Table 3.17 is used if the |
| 720 | // FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING |
| 721 | // is SRGB. |
| 722 | const InternalFormat *sourceEffectiveFormat = NULL; |
| 723 | if (readBufferHandle != 0) |
| 724 | { |
| 725 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer |
| 726 | if (framebufferInternalFormatInfo.pixelBytes > 0) |
| 727 | { |
| 728 | sourceEffectiveFormat = &framebufferInternalFormatInfo; |
| 729 | } |
| 730 | else |
| 731 | { |
| 732 | // Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format |
| 733 | // 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] | 734 | GLenum sizedInternalFormat = GetSizedInternalFormat(framebufferInternalFormatInfo.format, framebufferInternalFormatInfo.type); |
| 735 | sourceEffectiveFormat = &GetInternalFormatInfo(sizedInternalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | else |
| 739 | { |
| 740 | // The effective internal format must be derived from the source framebuffer's channel sizes. |
| 741 | // This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 742 | if (framebufferInternalFormatInfo.colorEncoding == GL_LINEAR) |
| 743 | { |
| 744 | GLenum effectiveFormat; |
| 745 | if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, &effectiveFormat)) |
| 746 | { |
| 747 | sourceEffectiveFormat = &GetInternalFormatInfo(effectiveFormat); |
| 748 | } |
| 749 | else |
| 750 | { |
| 751 | return false; |
| 752 | } |
| 753 | } |
| 754 | else if (framebufferInternalFormatInfo.colorEncoding == GL_SRGB) |
| 755 | { |
| 756 | // SRGB buffers can only be copied to sized format destinations according to table 3.18 |
| 757 | if ((textureInternalFormatInfo.pixelBytes > 0) && |
| 758 | (framebufferInternalFormatInfo.redBits >= 1 && framebufferInternalFormatInfo.redBits <= 8) && |
| 759 | (framebufferInternalFormatInfo.greenBits >= 1 && framebufferInternalFormatInfo.greenBits <= 8) && |
| 760 | (framebufferInternalFormatInfo.blueBits >= 1 && framebufferInternalFormatInfo.blueBits <= 8) && |
| 761 | (framebufferInternalFormatInfo.alphaBits >= 1 && framebufferInternalFormatInfo.alphaBits <= 8)) |
| 762 | { |
| 763 | sourceEffectiveFormat = &GetInternalFormatInfo(GL_SRGB8_ALPHA8); |
| 764 | } |
| 765 | else |
| 766 | { |
| 767 | return false; |
| 768 | } |
| 769 | } |
| 770 | else |
| 771 | { |
| 772 | UNREACHABLE(); |
| 773 | return false; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | if (textureInternalFormatInfo.pixelBytes > 0) |
| 778 | { |
| 779 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is sized, |
| 780 | // component sizes of the source and destination formats must exactly match |
| 781 | if (textureInternalFormatInfo.redBits != sourceEffectiveFormat->redBits || |
| 782 | textureInternalFormatInfo.greenBits != sourceEffectiveFormat->greenBits || |
| 783 | textureInternalFormatInfo.blueBits != sourceEffectiveFormat->blueBits || |
| 784 | textureInternalFormatInfo.alphaBits != sourceEffectiveFormat->alphaBits) |
| 785 | { |
| 786 | return false; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | |
| 791 | return true; // A conversion function exists, and no rule in the specification has precluded conversion |
| 792 | // between these formats. |
| 793 | } |
| 794 | |
| 795 | return false; |
| 796 | } |
| 797 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 798 | bool ValidateES3CopyTexImageParameters(Context *context, GLenum target, GLint level, GLenum internalformat, |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 799 | bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, |
| 800 | GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 801 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 802 | GLenum textureInternalFormat; |
| 803 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 804 | xoffset, yoffset, zoffset, x, y, width, height, |
| 805 | border, &textureInternalFormat)) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 806 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 807 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 808 | } |
| 809 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 810 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 811 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 812 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 813 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 814 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 815 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 816 | } |
| 817 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 818 | if (context->getState().getReadFramebuffer()->id() != 0 && |
| 819 | framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 820 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 821 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 822 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 823 | } |
| 824 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 825 | const gl::FramebufferAttachment *source = framebuffer->getReadColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 826 | GLenum colorbufferInternalFormat = source->getInternalFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 827 | |
| 828 | if (isSubImage) |
| 829 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 830 | if (!IsValidES3CopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat, |
| 831 | context->getState().getReadFramebuffer()->id())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 832 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 833 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 834 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 835 | } |
| 836 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 837 | else |
| 838 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 839 | if (!gl::IsValidES3CopyTexImageCombination(internalformat, colorbufferInternalFormat, |
| 840 | context->getState().getReadFramebuffer()->id())) |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 841 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 842 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 843 | return false; |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 847 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 848 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 849 | } |
| 850 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 851 | bool ValidateES3TexStorageParameters(Context *context, GLenum target, GLsizei levels, GLenum internalformat, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 852 | GLsizei width, GLsizei height, GLsizei depth) |
| 853 | { |
| 854 | if (width < 1 || height < 1 || depth < 1 || levels < 1) |
| 855 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 856 | context->recordError(Error(GL_INVALID_VALUE)); |
| 857 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1) |
| 861 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 862 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 863 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 864 | } |
| 865 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 866 | const gl::Caps &caps = context->getCaps(); |
| 867 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 868 | switch (target) |
| 869 | { |
| 870 | case GL_TEXTURE_2D: |
| 871 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 872 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 873 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 874 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 875 | context->recordError(Error(GL_INVALID_VALUE)); |
| 876 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | break; |
| 880 | |
Geoff Lang | 01c21d2 | 2013-09-24 11:52:16 -0400 | [diff] [blame] | 881 | case GL_TEXTURE_CUBE_MAP: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 882 | { |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 883 | if (width != height) |
| 884 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 885 | context->recordError(Error(GL_INVALID_VALUE)); |
| 886 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 887 | } |
| 888 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 889 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 890 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 891 | context->recordError(Error(GL_INVALID_VALUE)); |
| 892 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | break; |
| 896 | |
| 897 | case GL_TEXTURE_3D: |
| 898 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 899 | if (static_cast<GLuint>(width) > caps.max3DTextureSize || |
| 900 | static_cast<GLuint>(height) > caps.max3DTextureSize || |
| 901 | static_cast<GLuint>(depth) > caps.max3DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 902 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 903 | context->recordError(Error(GL_INVALID_VALUE)); |
| 904 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 905 | } |
| 906 | } |
| 907 | break; |
| 908 | |
| 909 | case GL_TEXTURE_2D_ARRAY: |
| 910 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 911 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 912 | static_cast<GLuint>(height) > caps.max2DTextureSize || |
| 913 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 914 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 915 | context->recordError(Error(GL_INVALID_VALUE)); |
| 916 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 917 | } |
| 918 | } |
| 919 | break; |
| 920 | |
| 921 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 922 | context->recordError(Error(GL_INVALID_ENUM)); |
| 923 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 924 | } |
| 925 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 926 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 927 | if (!texture || texture->id() == 0) |
| 928 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 929 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 930 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | if (texture->isImmutable()) |
| 934 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 935 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 936 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 937 | } |
| 938 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 939 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 940 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 941 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 942 | context->recordError(Error(GL_INVALID_ENUM)); |
| 943 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 944 | } |
| 945 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 946 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 947 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 948 | context->recordError(Error(GL_INVALID_ENUM)); |
| 949 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | return true; |
| 953 | } |
| 954 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 955 | bool ValidateFramebufferTextureLayer(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 956 | GLuint texture, GLint level, GLint layer) |
| 957 | { |
| 958 | if (context->getClientVersion() < 3) |
| 959 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 960 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 961 | return false; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 962 | } |
| 963 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 964 | if (layer < 0) |
| 965 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 966 | context->recordError(Error(GL_INVALID_VALUE)); |
| 967 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 971 | { |
| 972 | return false; |
| 973 | } |
| 974 | |
| 975 | const gl::Caps &caps = context->getCaps(); |
| 976 | if (texture != 0) |
| 977 | { |
| 978 | gl::Texture *tex = context->getTexture(texture); |
| 979 | ASSERT(tex); |
| 980 | |
| 981 | switch (tex->getTarget()) |
| 982 | { |
| 983 | case GL_TEXTURE_2D_ARRAY: |
| 984 | { |
| 985 | if (level > gl::log2(caps.max2DTextureSize)) |
| 986 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 987 | context->recordError(Error(GL_INVALID_VALUE)); |
| 988 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 992 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 993 | context->recordError(Error(GL_INVALID_VALUE)); |
| 994 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 995 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 996 | } |
| 997 | break; |
| 998 | |
| 999 | case GL_TEXTURE_3D: |
| 1000 | { |
| 1001 | if (level > gl::log2(caps.max3DTextureSize)) |
| 1002 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1003 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1004 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | if (static_cast<GLuint>(layer) >= caps.max3DTextureSize) |
| 1008 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1009 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1010 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1011 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1012 | } |
| 1013 | break; |
| 1014 | |
| 1015 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1016 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1017 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1018 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1019 | |
| 1020 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(tex->getTarget(), level)); |
| 1021 | if (internalFormatInfo.compressed) |
| 1022 | { |
| 1023 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1024 | return false; |
| 1025 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | return true; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1029 | } |
| 1030 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1031 | bool ValidES3ReadFormatType(Context *context, GLenum internalFormat, GLenum format, GLenum type) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1032 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1033 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 1034 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1035 | switch (format) |
| 1036 | { |
| 1037 | case GL_RGBA: |
| 1038 | switch (type) |
| 1039 | { |
| 1040 | case GL_UNSIGNED_BYTE: |
| 1041 | break; |
| 1042 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 1043 | if (internalFormat != GL_RGB10_A2) |
| 1044 | { |
| 1045 | return false; |
| 1046 | } |
| 1047 | break; |
Geoff Lang | 1ec57f8 | 2013-10-16 11:43:23 -0400 | [diff] [blame] | 1048 | case GL_FLOAT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1049 | if (internalFormatInfo.componentType != GL_FLOAT) |
Geoff Lang | 1ec57f8 | 2013-10-16 11:43:23 -0400 | [diff] [blame] | 1050 | { |
| 1051 | return false; |
| 1052 | } |
| 1053 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1054 | default: |
| 1055 | return false; |
| 1056 | } |
| 1057 | break; |
| 1058 | case GL_RGBA_INTEGER: |
| 1059 | switch (type) |
| 1060 | { |
| 1061 | case GL_INT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1062 | if (internalFormatInfo.componentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1063 | { |
| 1064 | return false; |
| 1065 | } |
| 1066 | break; |
| 1067 | case GL_UNSIGNED_INT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1068 | if (internalFormatInfo.componentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1069 | { |
| 1070 | return false; |
| 1071 | } |
| 1072 | break; |
| 1073 | default: |
| 1074 | return false; |
| 1075 | } |
| 1076 | break; |
| 1077 | case GL_BGRA_EXT: |
| 1078 | switch (type) |
| 1079 | { |
| 1080 | case GL_UNSIGNED_BYTE: |
| 1081 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 1082 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 1083 | break; |
| 1084 | default: |
| 1085 | return false; |
| 1086 | } |
| 1087 | break; |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1088 | case GL_RG_EXT: |
| 1089 | case GL_RED_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1090 | if (!context->getExtensions().textureRG) |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1091 | { |
| 1092 | return false; |
| 1093 | } |
| 1094 | switch (type) |
| 1095 | { |
| 1096 | case GL_UNSIGNED_BYTE: |
| 1097 | break; |
| 1098 | default: |
| 1099 | return false; |
| 1100 | } |
| 1101 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1102 | default: |
| 1103 | return false; |
| 1104 | } |
| 1105 | return true; |
| 1106 | } |
| 1107 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1108 | bool ValidateES3RenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples, |
| 1109 | GLenum internalformat, GLsizei width, GLsizei height) |
| 1110 | { |
| 1111 | if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, height)) |
| 1112 | { |
| 1113 | return false; |
| 1114 | } |
| 1115 | |
| 1116 | //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. |
| 1117 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1118 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0) |
| 1119 | { |
| 1120 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1121 | return false; |
| 1122 | } |
| 1123 | |
| 1124 | // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY. |
| 1125 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 1126 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 1127 | { |
| 1128 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1129 | return false; |
| 1130 | } |
| 1131 | |
| 1132 | return true; |
| 1133 | } |
| 1134 | |
Geoff Lang | 1ea584c | 2015-03-26 21:08:33 +0000 | [diff] [blame] | 1135 | bool ValidateInvalidateFramebufferParameters(Context *context, GLenum target, GLsizei numAttachments, |
| 1136 | const GLenum* attachments) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1137 | { |
| 1138 | bool defaultFramebuffer = false; |
| 1139 | |
| 1140 | switch (target) |
| 1141 | { |
| 1142 | case GL_DRAW_FRAMEBUFFER: |
| 1143 | case GL_FRAMEBUFFER: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1144 | defaultFramebuffer = context->getState().getDrawFramebuffer()->id() == 0; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1145 | break; |
| 1146 | case GL_READ_FRAMEBUFFER: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1147 | defaultFramebuffer = context->getState().getReadFramebuffer()->id() == 0; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1148 | break; |
| 1149 | default: |
Geoff Lang | 1ea584c | 2015-03-26 21:08:33 +0000 | [diff] [blame] | 1150 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1151 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1152 | } |
| 1153 | |
Geoff Lang | 1ea584c | 2015-03-26 21:08:33 +0000 | [diff] [blame] | 1154 | for (int i = 0; i < numAttachments; ++i) |
| 1155 | { |
| 1156 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15) |
| 1157 | { |
| 1158 | if (defaultFramebuffer) |
| 1159 | { |
| 1160 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1161 | return false; |
| 1162 | } |
| 1163 | |
| 1164 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 1165 | { |
| 1166 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1167 | return false; |
| 1168 | } |
| 1169 | } |
| 1170 | else |
| 1171 | { |
| 1172 | switch (attachments[i]) |
| 1173 | { |
| 1174 | case GL_DEPTH_ATTACHMENT: |
| 1175 | case GL_STENCIL_ATTACHMENT: |
| 1176 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1177 | if (defaultFramebuffer) |
| 1178 | { |
| 1179 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1180 | return false; |
| 1181 | } |
| 1182 | break; |
| 1183 | case GL_COLOR: |
| 1184 | case GL_DEPTH: |
| 1185 | case GL_STENCIL: |
| 1186 | if (!defaultFramebuffer) |
| 1187 | { |
| 1188 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1189 | return false; |
| 1190 | } |
| 1191 | break; |
| 1192 | default: |
| 1193 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1194 | return false; |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1200 | } |
| 1201 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1202 | bool ValidateClearBuffer(Context *context) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1203 | { |
| 1204 | if (context->getClientVersion() < 3) |
| 1205 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1206 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1207 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1208 | } |
| 1209 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1210 | const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1211 | if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1212 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1213 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1214 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | return true; |
| 1218 | } |
| 1219 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1220 | bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1221 | { |
| 1222 | if (context->getClientVersion() < 3) |
| 1223 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1224 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1225 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1228 | return ValidateGetUniformBase(context, program, location); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1229 | } |
| 1230 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1231 | bool ValidateReadBuffer(Context *context, GLenum src) |
| 1232 | { |
| 1233 | if (context->getClientVersion() < 3) |
| 1234 | { |
| 1235 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1236 | return false; |
| 1237 | } |
| 1238 | |
| 1239 | Framebuffer *readFBO = context->getState().getReadFramebuffer(); |
| 1240 | |
| 1241 | if (readFBO == nullptr) |
| 1242 | { |
| 1243 | context->recordError(gl::Error(GL_INVALID_OPERATION, "No active read framebuffer.")); |
| 1244 | return false; |
| 1245 | } |
| 1246 | |
| 1247 | if (src == GL_NONE) |
| 1248 | { |
| 1249 | return true; |
| 1250 | } |
| 1251 | |
| 1252 | if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT15)) |
| 1253 | { |
| 1254 | context->recordError(gl::Error(GL_INVALID_ENUM, "Unknown enum for 'src' in ReadBuffer")); |
| 1255 | return false; |
| 1256 | } |
| 1257 | |
| 1258 | if (readFBO->id() == 0) |
| 1259 | { |
| 1260 | if (src != GL_BACK) |
| 1261 | { |
| 1262 | const char *errorMsg = "'src' must be GL_NONE or GL_BACK when reading from the default framebuffer."; |
| 1263 | context->recordError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
| 1264 | return false; |
| 1265 | } |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0); |
| 1270 | |
| 1271 | if (drawBuffer >= context->getCaps().maxDrawBuffers) |
| 1272 | { |
| 1273 | const char *errorMsg = "'src' is greater than MAX_DRAW_BUFFERS."; |
| 1274 | context->recordError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
| 1275 | return false; |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | return true; |
| 1280 | } |
| 1281 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1282 | } |