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