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