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