Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES3.h" |
| 10 | #include "libANGLE/validationES.h" |
| 11 | #include "libANGLE/Context.h" |
| 12 | #include "libANGLE/Texture.h" |
| 13 | #include "libANGLE/Framebuffer.h" |
| 14 | #include "libANGLE/Renderbuffer.h" |
| 15 | #include "libANGLE/formatutils.h" |
| 16 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 17 | |
| 18 | #include "common/mathutil.h" |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 19 | #include "common/utilities.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 20 | |
| 21 | namespace gl |
| 22 | { |
| 23 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 24 | struct ES3FormatCombination |
| 25 | { |
| 26 | GLenum internalFormat; |
| 27 | GLenum format; |
| 28 | GLenum type; |
| 29 | }; |
| 30 | |
| 31 | bool operator<(const ES3FormatCombination& a, const ES3FormatCombination& b) |
| 32 | { |
| 33 | return memcmp(&a, &b, sizeof(ES3FormatCombination)) < 0; |
| 34 | } |
| 35 | |
| 36 | typedef std::set<ES3FormatCombination> ES3FormatCombinationSet; |
| 37 | |
| 38 | static inline void InsertES3FormatCombo(ES3FormatCombinationSet *set, GLenum internalFormat, GLenum format, GLenum type) |
| 39 | { |
| 40 | ES3FormatCombination info; |
| 41 | info.internalFormat = internalFormat; |
| 42 | info.format = format; |
| 43 | info.type = type; |
| 44 | set->insert(info); |
| 45 | } |
| 46 | |
| 47 | ES3FormatCombinationSet BuildES3FormatSet() |
| 48 | { |
| 49 | ES3FormatCombinationSet set; |
| 50 | |
| 51 | // Format combinations from ES 3.0.1 spec, table 3.2 |
| 52 | |
| 53 | // | Internal format | Format | Type | |
| 54 | // | | | | |
| 55 | InsertES3FormatCombo(&set, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 56 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 57 | InsertES3FormatCombo(&set, GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 58 | InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 59 | InsertES3FormatCombo(&set, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ); |
| 60 | InsertES3FormatCombo(&set, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ); |
| 61 | InsertES3FormatCombo(&set, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 62 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 63 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ); |
| 64 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ); |
| 65 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT_OES ); |
| 66 | InsertES3FormatCombo(&set, GL_RGBA32F, GL_RGBA, GL_FLOAT ); |
| 67 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_FLOAT ); |
| 68 | InsertES3FormatCombo(&set, GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ); |
| 69 | InsertES3FormatCombo(&set, GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ); |
| 70 | InsertES3FormatCombo(&set, GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ); |
| 71 | InsertES3FormatCombo(&set, GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ); |
| 72 | InsertES3FormatCombo(&set, GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ); |
| 73 | InsertES3FormatCombo(&set, GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ); |
| 74 | InsertES3FormatCombo(&set, GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 75 | InsertES3FormatCombo(&set, GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ); |
| 76 | InsertES3FormatCombo(&set, GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ); |
| 77 | InsertES3FormatCombo(&set, GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ); |
| 78 | InsertES3FormatCombo(&set, GL_RGB8_SNORM, GL_RGB, GL_BYTE ); |
| 79 | InsertES3FormatCombo(&set, GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ); |
| 80 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ); |
| 81 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ); |
| 82 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_HALF_FLOAT ); |
| 83 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_HALF_FLOAT_OES ); |
| 84 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ); |
| 85 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT_OES ); |
| 86 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ); |
| 87 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT_OES ); |
| 88 | InsertES3FormatCombo(&set, GL_RGB32F, GL_RGB, GL_FLOAT ); |
| 89 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_FLOAT ); |
| 90 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ); |
| 91 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_FLOAT ); |
| 92 | InsertES3FormatCombo(&set, GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ); |
| 93 | InsertES3FormatCombo(&set, GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ); |
| 94 | InsertES3FormatCombo(&set, GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ); |
| 95 | InsertES3FormatCombo(&set, GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ); |
| 96 | InsertES3FormatCombo(&set, GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ); |
| 97 | InsertES3FormatCombo(&set, GL_RGB32I, GL_RGB_INTEGER, GL_INT ); |
| 98 | InsertES3FormatCombo(&set, GL_RG8, GL_RG, GL_UNSIGNED_BYTE ); |
| 99 | InsertES3FormatCombo(&set, GL_RG8_SNORM, GL_RG, GL_BYTE ); |
| 100 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_HALF_FLOAT ); |
| 101 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_HALF_FLOAT_OES ); |
| 102 | InsertES3FormatCombo(&set, GL_RG32F, GL_RG, GL_FLOAT ); |
| 103 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_FLOAT ); |
| 104 | InsertES3FormatCombo(&set, GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ); |
| 105 | InsertES3FormatCombo(&set, GL_RG8I, GL_RG_INTEGER, GL_BYTE ); |
| 106 | InsertES3FormatCombo(&set, GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ); |
| 107 | InsertES3FormatCombo(&set, GL_RG16I, GL_RG_INTEGER, GL_SHORT ); |
| 108 | InsertES3FormatCombo(&set, GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ); |
| 109 | InsertES3FormatCombo(&set, GL_RG32I, GL_RG_INTEGER, GL_INT ); |
| 110 | InsertES3FormatCombo(&set, GL_R8, GL_RED, GL_UNSIGNED_BYTE ); |
| 111 | InsertES3FormatCombo(&set, GL_R8_SNORM, GL_RED, GL_BYTE ); |
| 112 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_HALF_FLOAT ); |
| 113 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_HALF_FLOAT_OES ); |
| 114 | InsertES3FormatCombo(&set, GL_R32F, GL_RED, GL_FLOAT ); |
| 115 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_FLOAT ); |
| 116 | InsertES3FormatCombo(&set, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ); |
| 117 | InsertES3FormatCombo(&set, GL_R8I, GL_RED_INTEGER, GL_BYTE ); |
| 118 | InsertES3FormatCombo(&set, GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ); |
| 119 | InsertES3FormatCombo(&set, GL_R16I, GL_RED_INTEGER, GL_SHORT ); |
| 120 | InsertES3FormatCombo(&set, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ); |
| 121 | InsertES3FormatCombo(&set, GL_R32I, GL_RED_INTEGER, GL_INT ); |
| 122 | |
| 123 | // Unsized formats |
| 124 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 125 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ); |
| 126 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ); |
| 127 | InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ); |
| 128 | InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ); |
| 129 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ); |
| 130 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ); |
| 131 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ); |
| 132 | InsertES3FormatCombo(&set, GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ); |
| 133 | InsertES3FormatCombo(&set, GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE ); |
Jamie Madill | 689325c | 2015-07-20 14:36:53 -0400 | [diff] [blame] | 134 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_UNSIGNED_BYTE ); |
| 135 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_FLOAT ); |
| 136 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_HALF_FLOAT ); |
| 137 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_HALF_FLOAT_OES ); |
| 138 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_UNSIGNED_BYTE ); |
| 139 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_FLOAT ); |
| 140 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_HALF_FLOAT ); |
| 141 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_HALF_FLOAT_OES ); |
| 142 | InsertES3FormatCombo(&set, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 143 | |
| 144 | // Depth stencil formats |
| 145 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ); |
| 146 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); |
| 147 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); |
| 148 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ); |
| 149 | InsertES3FormatCombo(&set, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ); |
| 150 | InsertES3FormatCombo(&set, GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV); |
| 151 | |
| 152 | // From GL_EXT_sRGB |
| 153 | InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ); |
| 154 | InsertES3FormatCombo(&set, GL_SRGB8, GL_SRGB_EXT, GL_UNSIGNED_BYTE ); |
| 155 | |
| 156 | // From GL_OES_texture_float |
Jeff Muizelaar | bb1a5be | 2015-12-02 12:03:46 -0500 | [diff] [blame] | 157 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_FLOAT ); |
| 158 | InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_FLOAT ); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 159 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ); |
| 160 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ); |
| 161 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_FLOAT ); |
| 162 | |
| 163 | // From GL_OES_texture_half_float |
| 164 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ); |
| 165 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES ); |
| 166 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ); |
| 167 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES ); |
| 168 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ); |
| 169 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES ); |
| 170 | |
| 171 | // From GL_EXT_texture_format_BGRA8888 |
| 172 | InsertES3FormatCombo(&set, GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 173 | |
| 174 | // From GL_EXT_texture_storage |
| 175 | // | Internal format | Format | Type | |
| 176 | // | | | | |
| 177 | InsertES3FormatCombo(&set, GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ); |
| 178 | InsertES3FormatCombo(&set, GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ); |
| 179 | InsertES3FormatCombo(&set, GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ); |
| 180 | InsertES3FormatCombo(&set, GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ); |
| 181 | InsertES3FormatCombo(&set, GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ); |
| 182 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ); |
| 183 | InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ); |
| 184 | InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT_OES ); |
| 185 | InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ); |
| 186 | InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT_OES ); |
| 187 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ); |
| 188 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES ); |
| 189 | |
| 190 | // From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888 |
| 191 | InsertES3FormatCombo(&set, GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 192 | InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT); |
| 193 | InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 194 | InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT); |
| 195 | InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 196 | |
| 197 | // From GL_ANGLE_depth_texture |
| 198 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ); |
| 199 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 200 | return set; |
| 201 | } |
| 202 | |
| 203 | static bool ValidateTexImageFormatCombination(gl::Context *context, GLenum internalFormat, GLenum format, GLenum type) |
| 204 | { |
| 205 | // Note: dEQP 2013.4 expects an INVALID_VALUE error for TexImage3D with an invalid |
| 206 | // internal format. (dEQP-GLES3.functional.negative_api.texture.teximage3d) |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 207 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 208 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 209 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 210 | context->recordError(Error(GL_INVALID_ENUM)); |
| 211 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | // The type and format are valid if any supported internal format has that type and format |
| 215 | bool formatSupported = false; |
| 216 | bool typeSupported = false; |
| 217 | |
| 218 | static const ES3FormatCombinationSet es3FormatSet = BuildES3FormatSet(); |
| 219 | for (ES3FormatCombinationSet::const_iterator i = es3FormatSet.begin(); i != es3FormatSet.end(); i++) |
| 220 | { |
| 221 | if (i->format == format || i->type == type) |
| 222 | { |
| 223 | const gl::InternalFormat &info = gl::GetInternalFormatInfo(i->internalFormat); |
| 224 | bool supported = info.textureSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 225 | if (supported && i->type == type) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 226 | { |
| 227 | typeSupported = true; |
| 228 | } |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 229 | if (supported && i->format == format) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 230 | { |
| 231 | formatSupported = true; |
| 232 | } |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 233 | |
| 234 | // Early-out if both type and format are supported now |
| 235 | if (typeSupported && formatSupported) |
| 236 | { |
| 237 | break; |
| 238 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | if (!typeSupported || !formatSupported) |
| 243 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 244 | context->recordError(Error(GL_INVALID_ENUM)); |
| 245 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | // Check if this is a valid format combination to load texture data |
| 249 | ES3FormatCombination searchFormat; |
| 250 | searchFormat.internalFormat = internalFormat; |
| 251 | searchFormat.format = format; |
| 252 | searchFormat.type = type; |
| 253 | |
| 254 | if (es3FormatSet.find(searchFormat) == es3FormatSet.end()) |
| 255 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 256 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 257 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | return true; |
| 261 | } |
| 262 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 263 | 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] | 264 | GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 265 | GLint border, GLenum format, GLenum type, const GLvoid *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 266 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 267 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 268 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 269 | context->recordError(Error(GL_INVALID_ENUM)); |
| 270 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 273 | // Validate image size |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 274 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 275 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 276 | context->recordError(Error(GL_INVALID_VALUE)); |
| 277 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 280 | // Verify zero border |
| 281 | if (border != 0) |
| 282 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 283 | context->recordError(Error(GL_INVALID_VALUE)); |
| 284 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 285 | } |
| 286 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 287 | if (xoffset < 0 || yoffset < 0 || zoffset < 0 || |
| 288 | std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 289 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 290 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 291 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 292 | context->recordError(Error(GL_INVALID_VALUE)); |
| 293 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 296 | const gl::Caps &caps = context->getCaps(); |
| 297 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 298 | switch (target) |
| 299 | { |
| 300 | case GL_TEXTURE_2D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 301 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 302 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 303 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 304 | context->recordError(Error(GL_INVALID_VALUE)); |
| 305 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 306 | } |
| 307 | break; |
| 308 | |
| 309 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 310 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 311 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 312 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 313 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 314 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 315 | if (!isSubImage && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 316 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 317 | context->recordError(Error(GL_INVALID_VALUE)); |
| 318 | return false; |
| 319 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 320 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 321 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level)) |
| 322 | { |
| 323 | context->recordError(Error(GL_INVALID_VALUE)); |
| 324 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 325 | } |
| 326 | break; |
| 327 | |
| 328 | case GL_TEXTURE_3D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 329 | if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) || |
| 330 | static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) || |
| 331 | static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level)) |
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; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 335 | } |
| 336 | break; |
| 337 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 338 | case GL_TEXTURE_2D_ARRAY: |
| 339 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 340 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) || |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 341 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 342 | { |
| 343 | context->recordError(Error(GL_INVALID_VALUE)); |
| 344 | return false; |
| 345 | } |
| 346 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 347 | |
| 348 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 349 | context->recordError(Error(GL_INVALID_ENUM)); |
| 350 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 351 | } |
| 352 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 353 | gl::Texture *texture = context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 354 | if (!texture) |
| 355 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 356 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 357 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 358 | } |
| 359 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 360 | if (texture->getImmutableFormat() && !isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 361 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 362 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 363 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | // Validate texture formats |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 367 | GLenum actualInternalFormat = isSubImage ? texture->getInternalFormat(target, level) : internalformat; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 368 | const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 369 | if (isCompressed) |
| 370 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 371 | if (!actualFormatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 372 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 373 | context->recordError(Error( |
| 374 | GL_INVALID_ENUM, "internalformat is not a supported compressed internal format.")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 375 | return false; |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 376 | } |
| 377 | |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 378 | if (!ValidCompressedImageSize(context, actualInternalFormat, width, height)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 379 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 380 | context->recordError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 381 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 382 | } |
| 383 | |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 384 | if (!actualFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 385 | { |
| 386 | context->recordError(Error(GL_INVALID_ENUM)); |
| 387 | return false; |
| 388 | } |
| 389 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 390 | if (target == GL_TEXTURE_3D) |
| 391 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 392 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 393 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | else |
| 397 | { |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 398 | if (!ValidateTexImageFormatCombination(context, actualInternalFormat, format, type)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 399 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 400 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL)) |
| 404 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 405 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 406 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | // Validate sub image parameters |
| 411 | if (isSubImage) |
| 412 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 413 | if (isCompressed != actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 414 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 415 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 416 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 417 | } |
| 418 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 419 | if (width == 0 || height == 0 || depth == 0) |
| 420 | { |
| 421 | return false; |
| 422 | } |
| 423 | |
| 424 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 425 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 426 | context->recordError(Error(GL_INVALID_VALUE)); |
| 427 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 431 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 432 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 433 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 434 | context->recordError(Error(GL_INVALID_VALUE)); |
| 435 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 438 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 439 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 440 | static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 441 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 442 | context->recordError(Error(GL_INVALID_VALUE)); |
| 443 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 447 | // Check for pixel unpack buffer related API errors |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 448 | gl::Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 449 | if (pixelUnpackBuffer != NULL) |
| 450 | { |
| 451 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 452 | // would exceed the data store size. |
| 453 | size_t widthSize = static_cast<size_t>(width); |
| 454 | size_t heightSize = static_cast<size_t>(height); |
| 455 | size_t depthSize = static_cast<size_t>(depth); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 456 | GLenum sizedFormat = GetSizedInternalFormat(actualInternalFormat, type); |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 457 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 458 | size_t pixelBytes = static_cast<size_t>(gl::GetInternalFormatInfo(sizedFormat).pixelBytes); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 459 | |
| 460 | if (!rx::IsUnsignedMultiplicationSafe(widthSize, heightSize) || |
| 461 | !rx::IsUnsignedMultiplicationSafe(widthSize * heightSize, depthSize) || |
| 462 | !rx::IsUnsignedMultiplicationSafe(widthSize * heightSize * depthSize, pixelBytes)) |
| 463 | { |
| 464 | // Overflow past the end of the buffer |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 465 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 466 | return false; |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 467 | } |
| 468 | |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 469 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat); |
| 470 | size_t copyBytes = formatInfo.computeBlockSize(type, width, height); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 471 | size_t offset = reinterpret_cast<size_t>(pixels); |
| 472 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 473 | if (!rx::IsUnsignedAdditionSafe(offset, copyBytes) || |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 474 | ((offset + copyBytes) > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 475 | { |
| 476 | // Overflow past the end of the buffer |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 477 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 478 | return false; |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | // ...data is not evenly divisible into the number of bytes needed to store in memory a datum |
| 482 | // indicated by type. |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 483 | if (!isCompressed) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 484 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 485 | size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes); |
| 486 | |
| 487 | if ((offset % dataBytesPerPixel) != 0) |
| 488 | { |
| 489 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 490 | return false; |
| 491 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 492 | } |
| 493 | |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 494 | // ...the buffer object's data store is currently mapped. |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 495 | if (pixelUnpackBuffer->isMapped()) |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 496 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 497 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 498 | return false; |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 499 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 500 | } |
| 501 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 502 | return true; |
| 503 | } |
| 504 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 505 | struct EffectiveInternalFormatInfo |
| 506 | { |
| 507 | GLenum mEffectiveFormat; |
| 508 | GLenum mDestFormat; |
| 509 | GLuint mMinRedBits; |
| 510 | GLuint mMaxRedBits; |
| 511 | GLuint mMinGreenBits; |
| 512 | GLuint mMaxGreenBits; |
| 513 | GLuint mMinBlueBits; |
| 514 | GLuint mMaxBlueBits; |
| 515 | GLuint mMinAlphaBits; |
| 516 | GLuint mMaxAlphaBits; |
| 517 | |
| 518 | EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits, |
| 519 | GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits, |
| 520 | GLuint minAlphaBits, GLuint maxAlphaBits) |
| 521 | : mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits), |
| 522 | mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits), |
| 523 | mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits), |
| 524 | mMaxAlphaBits(maxAlphaBits) {}; |
| 525 | }; |
| 526 | |
| 527 | typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList; |
| 528 | |
| 529 | static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList() |
| 530 | { |
| 531 | EffectiveInternalFormatList list; |
| 532 | |
| 533 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 534 | // linear source buffer component sizes. |
| 535 | // | Source channel min/max sizes | |
| 536 | // Effective Internal Format | N/A | R | G | B | A | |
| 537 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8)); |
| 538 | list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0)); |
| 539 | list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0)); |
| 540 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0)); |
| 541 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0)); |
| 542 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 543 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 544 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8)); |
| 545 | list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2)); |
| 546 | |
| 547 | return list; |
| 548 | } |
| 549 | |
| 550 | static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList() |
| 551 | { |
| 552 | EffectiveInternalFormatList list; |
| 553 | |
| 554 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 555 | // linear source buffer component sizes. |
| 556 | // | Source channel min/max sizes | |
| 557 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 558 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 559 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX)); |
| 560 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 561 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX)); |
| 562 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX)); |
| 563 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 564 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 565 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8)); |
| 566 | |
| 567 | return list; |
| 568 | } |
| 569 | |
| 570 | static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, const InternalFormat &destFormat, |
| 571 | GLenum *outEffectiveFormat) |
| 572 | { |
| 573 | const EffectiveInternalFormatList *list = NULL; |
| 574 | GLenum targetFormat = GL_NONE; |
| 575 | |
| 576 | if (destFormat.pixelBytes > 0) |
| 577 | { |
| 578 | static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList(); |
| 579 | list = &sizedList; |
| 580 | } |
| 581 | else |
| 582 | { |
| 583 | static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList(); |
| 584 | list = &unsizedList; |
| 585 | targetFormat = destFormat.format; |
| 586 | } |
| 587 | |
| 588 | for (size_t curFormat = 0; curFormat < list->size(); ++curFormat) |
| 589 | { |
| 590 | const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat); |
| 591 | if ((formatInfo.mDestFormat == targetFormat) && |
| 592 | (formatInfo.mMinRedBits <= srcFormat.redBits && formatInfo.mMaxRedBits >= srcFormat.redBits) && |
| 593 | (formatInfo.mMinGreenBits <= srcFormat.greenBits && formatInfo.mMaxGreenBits >= srcFormat.greenBits) && |
| 594 | (formatInfo.mMinBlueBits <= srcFormat.blueBits && formatInfo.mMaxBlueBits >= srcFormat.blueBits) && |
| 595 | (formatInfo.mMinAlphaBits <= srcFormat.alphaBits && formatInfo.mMaxAlphaBits >= srcFormat.alphaBits)) |
| 596 | { |
| 597 | *outEffectiveFormat = formatInfo.mEffectiveFormat; |
| 598 | return true; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return false; |
| 603 | } |
| 604 | |
| 605 | struct CopyConversion |
| 606 | { |
| 607 | GLenum mTextureFormat; |
| 608 | GLenum mFramebufferFormat; |
| 609 | |
| 610 | CopyConversion(GLenum textureFormat, GLenum framebufferFormat) |
| 611 | : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { } |
| 612 | |
| 613 | bool operator<(const CopyConversion& other) const |
| 614 | { |
| 615 | return memcmp(this, &other, sizeof(CopyConversion)) < 0; |
| 616 | } |
| 617 | }; |
| 618 | |
| 619 | typedef std::set<CopyConversion> CopyConversionSet; |
| 620 | |
| 621 | static CopyConversionSet BuildValidES3CopyTexImageCombinations() |
| 622 | { |
| 623 | CopyConversionSet set; |
| 624 | |
| 625 | // From ES 3.0.1 spec, table 3.15 |
| 626 | set.insert(CopyConversion(GL_ALPHA, GL_RGBA)); |
| 627 | set.insert(CopyConversion(GL_LUMINANCE, GL_RED)); |
| 628 | set.insert(CopyConversion(GL_LUMINANCE, GL_RG)); |
| 629 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGB)); |
| 630 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA)); |
| 631 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA)); |
| 632 | set.insert(CopyConversion(GL_RED, GL_RED)); |
| 633 | set.insert(CopyConversion(GL_RED, GL_RG)); |
| 634 | set.insert(CopyConversion(GL_RED, GL_RGB)); |
| 635 | set.insert(CopyConversion(GL_RED, GL_RGBA)); |
| 636 | set.insert(CopyConversion(GL_RG, GL_RG)); |
| 637 | set.insert(CopyConversion(GL_RG, GL_RGB)); |
| 638 | set.insert(CopyConversion(GL_RG, GL_RGBA)); |
| 639 | set.insert(CopyConversion(GL_RGB, GL_RGB)); |
| 640 | set.insert(CopyConversion(GL_RGB, GL_RGBA)); |
| 641 | set.insert(CopyConversion(GL_RGBA, GL_RGBA)); |
| 642 | |
| 643 | // Necessary for ANGLE back-buffers |
| 644 | set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT)); |
| 645 | set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT)); |
| 646 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT)); |
| 647 | set.insert(CopyConversion(GL_RED, GL_BGRA_EXT)); |
| 648 | set.insert(CopyConversion(GL_RG, GL_BGRA_EXT)); |
| 649 | set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT)); |
| 650 | set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT)); |
| 651 | |
| 652 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER)); |
| 653 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER)); |
| 654 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER)); |
| 655 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER)); |
| 656 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER)); |
| 657 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER)); |
| 658 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER)); |
| 659 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER)); |
| 660 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER)); |
| 661 | set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER)); |
| 662 | |
| 663 | return set; |
| 664 | } |
| 665 | |
| 666 | static bool IsValidES3CopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle) |
| 667 | { |
| 668 | const InternalFormat &textureInternalFormatInfo = GetInternalFormatInfo(textureInternalFormat); |
| 669 | const InternalFormat &framebufferInternalFormatInfo = GetInternalFormatInfo(frameBufferInternalFormat); |
| 670 | |
| 671 | static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations(); |
| 672 | if (conversionSet.find(CopyConversion(textureInternalFormatInfo.format, framebufferInternalFormatInfo.format)) != conversionSet.end()) |
| 673 | { |
| 674 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 675 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 676 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 677 | // conversion between fixed and floating point. |
| 678 | |
| 679 | if ((textureInternalFormatInfo.colorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.colorEncoding == GL_SRGB)) |
| 680 | { |
| 681 | return false; |
| 682 | } |
| 683 | |
| 684 | if (((textureInternalFormatInfo.componentType == GL_INT) != (framebufferInternalFormatInfo.componentType == GL_INT )) || |
| 685 | ((textureInternalFormatInfo.componentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.componentType == GL_UNSIGNED_INT))) |
| 686 | { |
| 687 | return false; |
| 688 | } |
| 689 | |
| 690 | if ((textureInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 691 | textureInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 692 | textureInternalFormatInfo.componentType == GL_FLOAT) && |
| 693 | !(framebufferInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 694 | framebufferInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 695 | framebufferInternalFormatInfo.componentType == GL_FLOAT)) |
| 696 | { |
| 697 | return false; |
| 698 | } |
| 699 | |
| 700 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 701 | // The effective internal format of the source buffer is determined with the following rules applied in order: |
| 702 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the |
| 703 | // effective internal format is the source buffer's sized internal format. |
| 704 | // * If the source buffer is a texture that was created with an unsized base internal format, then the |
| 705 | // effective internal format is the source image array's effective internal format, as specified by table |
| 706 | // 3.12, which is determined from the <format> and <type> that were used when the source image array was |
| 707 | // specified by TexImage*. |
| 708 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where |
| 709 | // Destination Internal Format matches internalformat and where the [source channel sizes] are consistent |
| 710 | // with the values of the source buffer's [channel sizes]. Table 3.17 is used if the |
| 711 | // FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING |
| 712 | // is SRGB. |
| 713 | const InternalFormat *sourceEffectiveFormat = NULL; |
| 714 | if (readBufferHandle != 0) |
| 715 | { |
| 716 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer |
| 717 | if (framebufferInternalFormatInfo.pixelBytes > 0) |
| 718 | { |
| 719 | sourceEffectiveFormat = &framebufferInternalFormatInfo; |
| 720 | } |
| 721 | else |
| 722 | { |
| 723 | // Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format |
| 724 | // 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] | 725 | GLenum sizedInternalFormat = GetSizedInternalFormat(framebufferInternalFormatInfo.format, framebufferInternalFormatInfo.type); |
| 726 | sourceEffectiveFormat = &GetInternalFormatInfo(sizedInternalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | else |
| 730 | { |
| 731 | // The effective internal format must be derived from the source framebuffer's channel sizes. |
| 732 | // This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 733 | if (framebufferInternalFormatInfo.colorEncoding == GL_LINEAR) |
| 734 | { |
| 735 | GLenum effectiveFormat; |
| 736 | if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, &effectiveFormat)) |
| 737 | { |
| 738 | sourceEffectiveFormat = &GetInternalFormatInfo(effectiveFormat); |
| 739 | } |
| 740 | else |
| 741 | { |
| 742 | return false; |
| 743 | } |
| 744 | } |
| 745 | else if (framebufferInternalFormatInfo.colorEncoding == GL_SRGB) |
| 746 | { |
| 747 | // SRGB buffers can only be copied to sized format destinations according to table 3.18 |
| 748 | if ((textureInternalFormatInfo.pixelBytes > 0) && |
| 749 | (framebufferInternalFormatInfo.redBits >= 1 && framebufferInternalFormatInfo.redBits <= 8) && |
| 750 | (framebufferInternalFormatInfo.greenBits >= 1 && framebufferInternalFormatInfo.greenBits <= 8) && |
| 751 | (framebufferInternalFormatInfo.blueBits >= 1 && framebufferInternalFormatInfo.blueBits <= 8) && |
| 752 | (framebufferInternalFormatInfo.alphaBits >= 1 && framebufferInternalFormatInfo.alphaBits <= 8)) |
| 753 | { |
| 754 | sourceEffectiveFormat = &GetInternalFormatInfo(GL_SRGB8_ALPHA8); |
| 755 | } |
| 756 | else |
| 757 | { |
| 758 | return false; |
| 759 | } |
| 760 | } |
| 761 | else |
| 762 | { |
| 763 | UNREACHABLE(); |
| 764 | return false; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | if (textureInternalFormatInfo.pixelBytes > 0) |
| 769 | { |
| 770 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is sized, |
| 771 | // component sizes of the source and destination formats must exactly match |
| 772 | if (textureInternalFormatInfo.redBits != sourceEffectiveFormat->redBits || |
| 773 | textureInternalFormatInfo.greenBits != sourceEffectiveFormat->greenBits || |
| 774 | textureInternalFormatInfo.blueBits != sourceEffectiveFormat->blueBits || |
| 775 | textureInternalFormatInfo.alphaBits != sourceEffectiveFormat->alphaBits) |
| 776 | { |
| 777 | return false; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | |
| 782 | return true; // A conversion function exists, and no rule in the specification has precluded conversion |
| 783 | // between these formats. |
| 784 | } |
| 785 | |
| 786 | return false; |
| 787 | } |
| 788 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame^] | 789 | bool ValidateES3CopyTexImageParameters(ValidationContext *context, |
| 790 | GLenum target, |
| 791 | GLint level, |
| 792 | GLenum internalformat, |
| 793 | bool isSubImage, |
| 794 | GLint xoffset, |
| 795 | GLint yoffset, |
| 796 | GLint zoffset, |
| 797 | GLint x, |
| 798 | GLint y, |
| 799 | GLsizei width, |
| 800 | GLsizei height, |
| 801 | GLint border) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 802 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 803 | GLenum textureInternalFormat; |
| 804 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 805 | xoffset, yoffset, zoffset, x, y, width, height, |
| 806 | border, &textureInternalFormat)) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 807 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 808 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame^] | 811 | const auto &state = context->getState(); |
| 812 | const gl::Framebuffer *framebuffer = state.getReadFramebuffer(); |
| 813 | GLuint readFramebufferID = framebuffer->id(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 814 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 815 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 816 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 817 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 818 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 819 | } |
| 820 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame^] | 821 | if (readFramebufferID != 0 && framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 822 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 823 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 824 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 825 | } |
| 826 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 827 | const gl::FramebufferAttachment *source = framebuffer->getReadColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 828 | GLenum colorbufferInternalFormat = source->getInternalFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 829 | |
| 830 | if (isSubImage) |
| 831 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 832 | if (!IsValidES3CopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame^] | 833 | readFramebufferID)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 834 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 835 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 836 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 837 | } |
| 838 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 839 | else |
| 840 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 841 | if (!gl::IsValidES3CopyTexImageCombination(internalformat, colorbufferInternalFormat, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame^] | 842 | readFramebufferID)) |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 843 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 844 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 845 | return false; |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 849 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 850 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 851 | } |
| 852 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 853 | bool ValidateES3TexStorageParameters(Context *context, GLenum target, GLsizei levels, GLenum internalformat, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 854 | GLsizei width, GLsizei height, GLsizei depth) |
| 855 | { |
| 856 | if (width < 1 || height < 1 || depth < 1 || levels < 1) |
| 857 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 858 | context->recordError(Error(GL_INVALID_VALUE)); |
| 859 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 860 | } |
| 861 | |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 862 | GLsizei maxDim = std::max(width, height); |
| 863 | if (target != GL_TEXTURE_2D_ARRAY) |
| 864 | { |
| 865 | maxDim = std::max(maxDim, depth); |
| 866 | } |
| 867 | |
| 868 | if (levels > gl::log2(maxDim) + 1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 869 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 870 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 871 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 872 | } |
| 873 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 874 | const gl::Caps &caps = context->getCaps(); |
| 875 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 876 | switch (target) |
| 877 | { |
| 878 | case GL_TEXTURE_2D: |
| 879 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 880 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 881 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 882 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 883 | context->recordError(Error(GL_INVALID_VALUE)); |
| 884 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | break; |
| 888 | |
Geoff Lang | 01c21d2 | 2013-09-24 11:52:16 -0400 | [diff] [blame] | 889 | case GL_TEXTURE_CUBE_MAP: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 890 | { |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 891 | if (width != height) |
| 892 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 893 | context->recordError(Error(GL_INVALID_VALUE)); |
| 894 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 895 | } |
| 896 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 897 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize) |
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_VALUE)); |
| 900 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | break; |
| 904 | |
| 905 | case GL_TEXTURE_3D: |
| 906 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 907 | if (static_cast<GLuint>(width) > caps.max3DTextureSize || |
| 908 | static_cast<GLuint>(height) > caps.max3DTextureSize || |
| 909 | static_cast<GLuint>(depth) > caps.max3DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 910 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 911 | context->recordError(Error(GL_INVALID_VALUE)); |
| 912 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | break; |
| 916 | |
| 917 | case GL_TEXTURE_2D_ARRAY: |
| 918 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 919 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 920 | static_cast<GLuint>(height) > caps.max2DTextureSize || |
| 921 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 922 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 923 | context->recordError(Error(GL_INVALID_VALUE)); |
| 924 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | break; |
| 928 | |
| 929 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 930 | context->recordError(Error(GL_INVALID_ENUM)); |
| 931 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 932 | } |
| 933 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 934 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 935 | if (!texture || texture->id() == 0) |
| 936 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 937 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 938 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 939 | } |
| 940 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 941 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 942 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 943 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 944 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 945 | } |
| 946 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 947 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 948 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 949 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 950 | context->recordError(Error(GL_INVALID_ENUM)); |
| 951 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 954 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 955 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 956 | context->recordError(Error(GL_INVALID_ENUM)); |
| 957 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | return true; |
| 961 | } |
| 962 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 963 | bool ValidateFramebufferTextureLayer(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 964 | GLuint texture, GLint level, GLint layer) |
| 965 | { |
| 966 | if (context->getClientVersion() < 3) |
| 967 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 968 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 969 | return false; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 970 | } |
| 971 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 972 | if (layer < 0) |
| 973 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 974 | context->recordError(Error(GL_INVALID_VALUE)); |
| 975 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 979 | { |
| 980 | return false; |
| 981 | } |
| 982 | |
| 983 | const gl::Caps &caps = context->getCaps(); |
| 984 | if (texture != 0) |
| 985 | { |
| 986 | gl::Texture *tex = context->getTexture(texture); |
| 987 | ASSERT(tex); |
| 988 | |
| 989 | switch (tex->getTarget()) |
| 990 | { |
| 991 | case GL_TEXTURE_2D_ARRAY: |
| 992 | { |
| 993 | if (level > gl::log2(caps.max2DTextureSize)) |
| 994 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 995 | context->recordError(Error(GL_INVALID_VALUE)); |
| 996 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 1000 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1001 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1002 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1003 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1004 | } |
| 1005 | break; |
| 1006 | |
| 1007 | case GL_TEXTURE_3D: |
| 1008 | { |
| 1009 | if (level > gl::log2(caps.max3DTextureSize)) |
| 1010 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1011 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1012 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | if (static_cast<GLuint>(layer) >= caps.max3DTextureSize) |
| 1016 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1017 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1018 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1019 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1020 | } |
| 1021 | break; |
| 1022 | |
| 1023 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1024 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1025 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1026 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1027 | |
| 1028 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(tex->getTarget(), level)); |
| 1029 | if (internalFormatInfo.compressed) |
| 1030 | { |
| 1031 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1032 | return false; |
| 1033 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | return true; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1037 | } |
| 1038 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1039 | bool ValidES3ReadFormatType(Context *context, GLenum internalFormat, GLenum format, GLenum type) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1040 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1041 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 1042 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1043 | switch (format) |
| 1044 | { |
| 1045 | case GL_RGBA: |
| 1046 | switch (type) |
| 1047 | { |
| 1048 | case GL_UNSIGNED_BYTE: |
| 1049 | break; |
| 1050 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 1051 | if (internalFormat != GL_RGB10_A2) |
| 1052 | { |
| 1053 | return false; |
| 1054 | } |
| 1055 | break; |
Geoff Lang | 1ec57f8 | 2013-10-16 11:43:23 -0400 | [diff] [blame] | 1056 | case GL_FLOAT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1057 | if (internalFormatInfo.componentType != GL_FLOAT) |
Geoff Lang | 1ec57f8 | 2013-10-16 11:43:23 -0400 | [diff] [blame] | 1058 | { |
| 1059 | return false; |
| 1060 | } |
| 1061 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1062 | default: |
| 1063 | return false; |
| 1064 | } |
| 1065 | break; |
| 1066 | case GL_RGBA_INTEGER: |
| 1067 | switch (type) |
| 1068 | { |
| 1069 | case GL_INT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1070 | if (internalFormatInfo.componentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1071 | { |
| 1072 | return false; |
| 1073 | } |
| 1074 | break; |
| 1075 | case GL_UNSIGNED_INT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1076 | if (internalFormatInfo.componentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1077 | { |
| 1078 | return false; |
| 1079 | } |
| 1080 | break; |
| 1081 | default: |
| 1082 | return false; |
| 1083 | } |
| 1084 | break; |
| 1085 | case GL_BGRA_EXT: |
| 1086 | switch (type) |
| 1087 | { |
| 1088 | case GL_UNSIGNED_BYTE: |
| 1089 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 1090 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 1091 | break; |
| 1092 | default: |
| 1093 | return false; |
| 1094 | } |
| 1095 | break; |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1096 | case GL_RG_EXT: |
| 1097 | case GL_RED_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1098 | if (!context->getExtensions().textureRG) |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1099 | { |
| 1100 | return false; |
| 1101 | } |
| 1102 | switch (type) |
| 1103 | { |
| 1104 | case GL_UNSIGNED_BYTE: |
| 1105 | break; |
| 1106 | default: |
| 1107 | return false; |
| 1108 | } |
| 1109 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1110 | default: |
| 1111 | return false; |
| 1112 | } |
| 1113 | return true; |
| 1114 | } |
| 1115 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1116 | bool ValidateES3RenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples, |
| 1117 | GLenum internalformat, GLsizei width, GLsizei height) |
| 1118 | { |
| 1119 | if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, height)) |
| 1120 | { |
| 1121 | return false; |
| 1122 | } |
| 1123 | |
| 1124 | //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. |
| 1125 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1126 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0) |
| 1127 | { |
| 1128 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1129 | return false; |
| 1130 | } |
| 1131 | |
| 1132 | // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY. |
| 1133 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 1134 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 1135 | { |
| 1136 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1137 | return false; |
| 1138 | } |
| 1139 | |
| 1140 | return true; |
| 1141 | } |
| 1142 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1143 | bool ValidateInvalidateFramebuffer(Context *context, GLenum target, GLsizei numAttachments, |
| 1144 | const GLenum *attachments) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1145 | { |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1146 | if (context->getClientVersion() < 3) |
| 1147 | { |
| 1148 | context->recordError(Error(GL_INVALID_OPERATION, "Operation only supported on ES 3.0 and above")); |
| 1149 | return false; |
| 1150 | } |
| 1151 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1152 | bool defaultFramebuffer = false; |
| 1153 | |
| 1154 | switch (target) |
| 1155 | { |
| 1156 | case GL_DRAW_FRAMEBUFFER: |
| 1157 | case GL_FRAMEBUFFER: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1158 | defaultFramebuffer = context->getState().getDrawFramebuffer()->id() == 0; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1159 | break; |
| 1160 | case GL_READ_FRAMEBUFFER: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1161 | defaultFramebuffer = context->getState().getReadFramebuffer()->id() == 0; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1162 | break; |
| 1163 | default: |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1164 | context->recordError(Error(GL_INVALID_ENUM, "Invalid framebuffer target")); |
| 1165 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1166 | } |
| 1167 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1168 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, defaultFramebuffer); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1169 | } |
| 1170 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame^] | 1171 | bool ValidateClearBuffer(ValidationContext *context) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1172 | { |
| 1173 | if (context->getClientVersion() < 3) |
| 1174 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1175 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1176 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1177 | } |
| 1178 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1179 | const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1180 | if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1181 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1182 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1183 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | return true; |
| 1187 | } |
| 1188 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1189 | bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1190 | { |
| 1191 | if (context->getClientVersion() < 3) |
| 1192 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1193 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1194 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1197 | return ValidateGetUniformBase(context, program, location); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1198 | } |
| 1199 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1200 | bool ValidateReadBuffer(Context *context, GLenum src) |
| 1201 | { |
| 1202 | if (context->getClientVersion() < 3) |
| 1203 | { |
| 1204 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1205 | return false; |
| 1206 | } |
| 1207 | |
| 1208 | Framebuffer *readFBO = context->getState().getReadFramebuffer(); |
| 1209 | |
| 1210 | if (readFBO == nullptr) |
| 1211 | { |
| 1212 | context->recordError(gl::Error(GL_INVALID_OPERATION, "No active read framebuffer.")); |
| 1213 | return false; |
| 1214 | } |
| 1215 | |
| 1216 | if (src == GL_NONE) |
| 1217 | { |
| 1218 | return true; |
| 1219 | } |
| 1220 | |
| 1221 | if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT15)) |
| 1222 | { |
| 1223 | context->recordError(gl::Error(GL_INVALID_ENUM, "Unknown enum for 'src' in ReadBuffer")); |
| 1224 | return false; |
| 1225 | } |
| 1226 | |
| 1227 | if (readFBO->id() == 0) |
| 1228 | { |
| 1229 | if (src != GL_BACK) |
| 1230 | { |
| 1231 | const char *errorMsg = "'src' must be GL_NONE or GL_BACK when reading from the default framebuffer."; |
| 1232 | context->recordError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
| 1233 | return false; |
| 1234 | } |
| 1235 | } |
| 1236 | else |
| 1237 | { |
| 1238 | GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0); |
| 1239 | |
| 1240 | if (drawBuffer >= context->getCaps().maxDrawBuffers) |
| 1241 | { |
| 1242 | const char *errorMsg = "'src' is greater than MAX_DRAW_BUFFERS."; |
| 1243 | context->recordError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
| 1244 | return false; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | return true; |
| 1249 | } |
| 1250 | |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1251 | bool ValidateCompressedTexImage3D(Context *context, |
| 1252 | GLenum target, |
| 1253 | GLint level, |
| 1254 | GLenum internalformat, |
| 1255 | GLsizei width, |
| 1256 | GLsizei height, |
| 1257 | GLsizei depth, |
| 1258 | GLint border, |
| 1259 | GLsizei imageSize, |
| 1260 | const GLvoid *data) |
| 1261 | { |
| 1262 | if (context->getClientVersion() < 3) |
| 1263 | { |
| 1264 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1265 | return false; |
| 1266 | } |
| 1267 | |
| 1268 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
| 1269 | if (imageSize < 0 || |
| 1270 | static_cast<GLuint>(imageSize) != |
| 1271 | formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height)) |
| 1272 | { |
| 1273 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1274 | return false; |
| 1275 | } |
| 1276 | |
| 1277 | // 3D texture target validation |
| 1278 | if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) |
| 1279 | { |
| 1280 | context->recordError( |
| 1281 | Error(GL_INVALID_ENUM, "Must specify a valid 3D texture destination target")); |
| 1282 | return false; |
| 1283 | } |
| 1284 | |
| 1285 | // validateES3TexImageFormat sets the error code if there is an error |
| 1286 | if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false, 0, 0, 0, |
| 1287 | width, height, depth, border, GL_NONE, GL_NONE, data)) |
| 1288 | { |
| 1289 | return false; |
| 1290 | } |
| 1291 | |
| 1292 | return true; |
| 1293 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1294 | |
| 1295 | bool ValidateBindVertexArray(Context *context, GLuint array) |
| 1296 | { |
| 1297 | if (context->getClientVersion() < 3) |
| 1298 | { |
| 1299 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1300 | return false; |
| 1301 | } |
| 1302 | |
| 1303 | return ValidateBindVertexArrayBase(context, array); |
| 1304 | } |
| 1305 | |
| 1306 | bool ValidateDeleteVertexArrays(Context *context, GLsizei n) |
| 1307 | { |
| 1308 | if (context->getClientVersion() < 3) |
| 1309 | { |
| 1310 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1311 | return false; |
| 1312 | } |
| 1313 | |
| 1314 | return ValidateDeleteVertexArraysBase(context, n); |
| 1315 | } |
| 1316 | |
| 1317 | bool ValidateGenVertexArrays(Context *context, GLsizei n) |
| 1318 | { |
| 1319 | if (context->getClientVersion() < 3) |
| 1320 | { |
| 1321 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1322 | return false; |
| 1323 | } |
| 1324 | |
| 1325 | return ValidateGenVertexArraysBase(context, n); |
| 1326 | } |
| 1327 | |
| 1328 | bool ValidateIsVertexArray(Context *context) |
| 1329 | { |
| 1330 | if (context->getClientVersion() < 3) |
| 1331 | { |
| 1332 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1333 | return false; |
| 1334 | } |
| 1335 | |
| 1336 | return true; |
| 1337 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1338 | |
| 1339 | bool ValidateProgramBinary(Context *context, |
| 1340 | GLuint program, |
| 1341 | GLenum binaryFormat, |
| 1342 | const void *binary, |
| 1343 | GLint length) |
| 1344 | { |
| 1345 | if (context->getClientVersion() < 3) |
| 1346 | { |
| 1347 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1348 | return false; |
| 1349 | } |
| 1350 | |
| 1351 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1352 | } |
| 1353 | |
| 1354 | bool ValidateGetProgramBinary(Context *context, |
| 1355 | GLuint program, |
| 1356 | GLsizei bufSize, |
| 1357 | GLsizei *length, |
| 1358 | GLenum *binaryFormat, |
| 1359 | void *binary) |
| 1360 | { |
| 1361 | if (context->getClientVersion() < 3) |
| 1362 | { |
| 1363 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1364 | return false; |
| 1365 | } |
| 1366 | |
| 1367 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1368 | } |
| 1369 | |
| 1370 | bool ValidateProgramParameter(Context *context, GLuint program, GLenum pname, GLint value) |
| 1371 | { |
| 1372 | if (context->getClientVersion() < 3) |
| 1373 | { |
| 1374 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1375 | return false; |
| 1376 | } |
| 1377 | |
| 1378 | if (GetValidProgram(context, program) == nullptr) |
| 1379 | { |
| 1380 | return false; |
| 1381 | } |
| 1382 | |
| 1383 | switch (pname) |
| 1384 | { |
| 1385 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 1386 | break; |
| 1387 | |
| 1388 | default: |
| 1389 | context->recordError(Error(GL_INVALID_ENUM, "Invalid pname: 0x%X", pname)); |
| 1390 | return false; |
| 1391 | } |
| 1392 | |
| 1393 | return true; |
| 1394 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame^] | 1395 | |
| 1396 | bool ValidateBlitFramebuffer(Context *context, |
| 1397 | GLint srcX0, |
| 1398 | GLint srcY0, |
| 1399 | GLint srcX1, |
| 1400 | GLint srcY1, |
| 1401 | GLint dstX0, |
| 1402 | GLint dstY0, |
| 1403 | GLint dstX1, |
| 1404 | GLint dstY1, |
| 1405 | GLbitfield mask, |
| 1406 | GLenum filter) |
| 1407 | { |
| 1408 | if (context->getClientVersion() < 3) |
| 1409 | { |
| 1410 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1411 | return false; |
| 1412 | } |
| 1413 | |
| 1414 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 1415 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1416 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame^] | 1417 | |
| 1418 | bool ValidateClearBufferiv(ValidationContext *context, |
| 1419 | GLenum buffer, |
| 1420 | GLint drawbuffer, |
| 1421 | const GLint *value) |
| 1422 | { |
| 1423 | switch (buffer) |
| 1424 | { |
| 1425 | case GL_COLOR: |
| 1426 | if (drawbuffer < 0 || |
| 1427 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1428 | { |
| 1429 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1430 | return false; |
| 1431 | } |
| 1432 | break; |
| 1433 | |
| 1434 | case GL_STENCIL: |
| 1435 | if (drawbuffer != 0) |
| 1436 | { |
| 1437 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1438 | return false; |
| 1439 | } |
| 1440 | break; |
| 1441 | |
| 1442 | default: |
| 1443 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1444 | return false; |
| 1445 | } |
| 1446 | |
| 1447 | return ValidateClearBuffer(context); |
| 1448 | } |
| 1449 | |
| 1450 | bool ValidateClearBufferuiv(ValidationContext *context, |
| 1451 | GLenum buffer, |
| 1452 | GLint drawbuffer, |
| 1453 | const GLuint *value) |
| 1454 | { |
| 1455 | switch (buffer) |
| 1456 | { |
| 1457 | case GL_COLOR: |
| 1458 | if (drawbuffer < 0 || |
| 1459 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1460 | { |
| 1461 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1462 | return false; |
| 1463 | } |
| 1464 | break; |
| 1465 | |
| 1466 | default: |
| 1467 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1468 | return false; |
| 1469 | } |
| 1470 | |
| 1471 | return ValidateClearBuffer(context); |
| 1472 | } |
| 1473 | |
| 1474 | bool ValidateClearBufferfv(ValidationContext *context, |
| 1475 | GLenum buffer, |
| 1476 | GLint drawbuffer, |
| 1477 | const GLfloat *value) |
| 1478 | { |
| 1479 | switch (buffer) |
| 1480 | { |
| 1481 | case GL_COLOR: |
| 1482 | if (drawbuffer < 0 || |
| 1483 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1484 | { |
| 1485 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1486 | return false; |
| 1487 | } |
| 1488 | break; |
| 1489 | |
| 1490 | case GL_DEPTH: |
| 1491 | if (drawbuffer != 0) |
| 1492 | { |
| 1493 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1494 | return false; |
| 1495 | } |
| 1496 | break; |
| 1497 | |
| 1498 | default: |
| 1499 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1500 | return false; |
| 1501 | } |
| 1502 | |
| 1503 | return ValidateClearBuffer(context); |
| 1504 | } |
| 1505 | |
| 1506 | bool ValidateClearBufferfi(ValidationContext *context, |
| 1507 | GLenum buffer, |
| 1508 | GLint drawbuffer, |
| 1509 | GLfloat depth, |
| 1510 | GLint stencil) |
| 1511 | { |
| 1512 | switch (buffer) |
| 1513 | { |
| 1514 | case GL_DEPTH_STENCIL: |
| 1515 | if (drawbuffer != 0) |
| 1516 | { |
| 1517 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1518 | return false; |
| 1519 | } |
| 1520 | break; |
| 1521 | |
| 1522 | default: |
| 1523 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1524 | return false; |
| 1525 | } |
| 1526 | |
| 1527 | return ValidateClearBuffer(context); |
| 1528 | } |
| 1529 | |
| 1530 | bool ValidateDrawBuffers(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 1531 | { |
| 1532 | if (context->getClientVersion() < 3) |
| 1533 | { |
| 1534 | context->recordError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
| 1535 | return false; |
| 1536 | } |
| 1537 | |
| 1538 | return ValidateDrawBuffersBase(context, n, bufs); |
| 1539 | } |
| 1540 | |
| 1541 | bool ValidateCopyTexSubImage3D(Context *context, |
| 1542 | GLenum target, |
| 1543 | GLint level, |
| 1544 | GLint xoffset, |
| 1545 | GLint yoffset, |
| 1546 | GLint zoffset, |
| 1547 | GLint x, |
| 1548 | GLint y, |
| 1549 | GLsizei width, |
| 1550 | GLsizei height) |
| 1551 | { |
| 1552 | if (context->getClientVersion() < 3) |
| 1553 | { |
| 1554 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1555 | return false; |
| 1556 | } |
| 1557 | |
| 1558 | return ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 1559 | yoffset, zoffset, x, y, width, height, 0); |
| 1560 | } |
| 1561 | |
| 1562 | } // namespace gl |