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