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 | // validationES.h: Validation functions for generic OpenGL ES entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES.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/validationES2.h" |
| 12 | #include "libANGLE/validationES3.h" |
| 13 | #include "libANGLE/Context.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 14 | #include "libANGLE/Display.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 15 | #include "libANGLE/Texture.h" |
| 16 | #include "libANGLE/Framebuffer.h" |
| 17 | #include "libANGLE/FramebufferAttachment.h" |
| 18 | #include "libANGLE/formatutils.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 19 | #include "libANGLE/Image.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/Query.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 21 | #include "libANGLE/Program.h" |
| 22 | #include "libANGLE/Uniform.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 23 | #include "libANGLE/TransformFeedback.h" |
| 24 | #include "libANGLE/VertexArray.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 25 | |
| 26 | #include "common/mathutil.h" |
| 27 | #include "common/utilities.h" |
| 28 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 29 | using namespace angle; |
| 30 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 31 | namespace gl |
| 32 | { |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 33 | const char *g_ExceedsMaxElementErrorMessage = "Element value exceeds maximum element index."; |
| 34 | |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 35 | namespace |
| 36 | { |
Jamie Madill | f25855c | 2015-11-03 11:06:18 -0500 | [diff] [blame] | 37 | bool ValidateDrawAttribs(ValidationContext *context, GLint primcount, GLint maxVertex) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 38 | { |
| 39 | const gl::State &state = context->getState(); |
| 40 | const gl::Program *program = state.getProgram(); |
| 41 | |
| 42 | const VertexArray *vao = state.getVertexArray(); |
| 43 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 44 | size_t maxEnabledAttrib = vao->getMaxEnabledAttribute(); |
| 45 | for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex) |
| 46 | { |
| 47 | const VertexAttribute &attrib = vertexAttribs[attributeIndex]; |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 48 | if (program->isAttribLocationActive(attributeIndex) && attrib.enabled) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 49 | { |
| 50 | gl::Buffer *buffer = attrib.buffer.get(); |
| 51 | |
| 52 | if (buffer) |
| 53 | { |
| 54 | GLint64 attribStride = static_cast<GLint64>(ComputeVertexAttributeStride(attrib)); |
| 55 | GLint64 maxVertexElement = 0; |
| 56 | |
| 57 | if (attrib.divisor > 0) |
| 58 | { |
| 59 | maxVertexElement = |
| 60 | static_cast<GLint64>(primcount) / static_cast<GLint64>(attrib.divisor); |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | maxVertexElement = static_cast<GLint64>(maxVertex); |
| 65 | } |
| 66 | |
| 67 | // If we're drawing zero vertices, we have enough data. |
| 68 | if (maxVertexElement > 0) |
| 69 | { |
| 70 | // Note: Last vertex element does not take the full stride! |
| 71 | GLint64 attribSize = |
| 72 | static_cast<GLint64>(ComputeVertexAttributeTypeSize(attrib)); |
| 73 | GLint64 attribDataSize = (maxVertexElement - 1) * attribStride + attribSize; |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 74 | GLint64 attribOffset = static_cast<GLint64>(attrib.offset); |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 75 | |
| 76 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 77 | // We can return INVALID_OPERATION if our vertex attribute does not have |
| 78 | // enough backing data. |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 79 | if (attribDataSize + attribOffset > buffer->getSize()) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 80 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 81 | context->handleError( |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 82 | Error(GL_INVALID_OPERATION, |
| 83 | "Vertex buffer is not big enough for the draw call")); |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 84 | return false; |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | else if (attrib.pointer == NULL) |
| 89 | { |
| 90 | // This is an application error that would normally result in a crash, |
| 91 | // but we catch it and return an error |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 92 | context->handleError(Error( |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 93 | GL_INVALID_OPERATION, "An enabled vertex array has no buffer and no pointer.")); |
| 94 | return false; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | } // anonymous namespace |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 103 | |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 104 | bool ValidCap(const Context *context, GLenum cap) |
| 105 | { |
| 106 | switch (cap) |
| 107 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 108 | // EXT_multisample_compatibility |
| 109 | case GL_MULTISAMPLE_EXT: |
| 110 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 111 | return context->getExtensions().multisampleCompatibility; |
| 112 | |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 113 | case GL_CULL_FACE: |
| 114 | case GL_POLYGON_OFFSET_FILL: |
| 115 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 116 | case GL_SAMPLE_COVERAGE: |
| 117 | case GL_SCISSOR_TEST: |
| 118 | case GL_STENCIL_TEST: |
| 119 | case GL_DEPTH_TEST: |
| 120 | case GL_BLEND: |
| 121 | case GL_DITHER: |
| 122 | return true; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 123 | |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 124 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 125 | case GL_RASTERIZER_DISCARD: |
| 126 | return (context->getClientVersion() >= 3); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 127 | |
| 128 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 129 | case GL_DEBUG_OUTPUT: |
| 130 | return context->getExtensions().debug; |
| 131 | |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 132 | default: |
| 133 | return false; |
| 134 | } |
| 135 | } |
| 136 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 137 | bool ValidTextureTarget(const ValidationContext *context, GLenum target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 138 | { |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 139 | switch (target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 140 | { |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 141 | case GL_TEXTURE_2D: |
| 142 | case GL_TEXTURE_CUBE_MAP: |
| 143 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 144 | |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 145 | case GL_TEXTURE_3D: |
| 146 | case GL_TEXTURE_2D_ARRAY: |
| 147 | return (context->getClientVersion() >= 3); |
| 148 | |
| 149 | default: |
| 150 | return false; |
| 151 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 152 | } |
| 153 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 154 | bool ValidTexture2DTarget(const ValidationContext *context, GLenum target) |
| 155 | { |
| 156 | switch (target) |
| 157 | { |
| 158 | case GL_TEXTURE_2D: |
| 159 | case GL_TEXTURE_CUBE_MAP: |
| 160 | return true; |
| 161 | |
| 162 | default: |
| 163 | return false; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | bool ValidTexture3DTarget(const ValidationContext *context, GLenum target) |
| 168 | { |
| 169 | switch (target) |
| 170 | { |
| 171 | case GL_TEXTURE_3D: |
| 172 | case GL_TEXTURE_2D_ARRAY: |
| 173 | return (context->getClientVersion() >= 3); |
| 174 | |
| 175 | default: |
| 176 | return false; |
| 177 | } |
| 178 | } |
| 179 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 180 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 181 | // function for use in the GL calls that do |
| 182 | bool ValidTextureExternalTarget(const ValidationContext *context, GLenum target) |
| 183 | { |
| 184 | return (target == GL_TEXTURE_EXTERNAL_OES) && |
| 185 | (context->getExtensions().eglImageExternal || |
| 186 | context->getExtensions().eglStreamConsumerExternal); |
| 187 | } |
| 188 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 189 | // This function differs from ValidTextureTarget in that the target must be |
| 190 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 191 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 192 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 193 | bool ValidTexture2DDestinationTarget(const ValidationContext *context, GLenum target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 194 | { |
| 195 | switch (target) |
| 196 | { |
| 197 | case GL_TEXTURE_2D: |
| 198 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 199 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 200 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 201 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 202 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 203 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 204 | return true; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 205 | default: |
| 206 | return false; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | bool ValidTexture3DDestinationTarget(const ValidationContext *context, GLenum target) |
| 211 | { |
| 212 | switch (target) |
| 213 | { |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 214 | case GL_TEXTURE_3D: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 215 | case GL_TEXTURE_2D_ARRAY: |
| 216 | return true; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 217 | default: |
| 218 | return false; |
| 219 | } |
| 220 | } |
| 221 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 222 | bool ValidFramebufferTarget(GLenum target) |
| 223 | { |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 224 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
| 225 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 226 | |
| 227 | switch (target) |
| 228 | { |
| 229 | case GL_FRAMEBUFFER: return true; |
| 230 | case GL_READ_FRAMEBUFFER: return true; |
| 231 | case GL_DRAW_FRAMEBUFFER: return true; |
| 232 | default: return false; |
| 233 | } |
| 234 | } |
| 235 | |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 236 | bool ValidBufferTarget(const Context *context, GLenum target) |
| 237 | { |
| 238 | switch (target) |
| 239 | { |
| 240 | case GL_ARRAY_BUFFER: |
| 241 | case GL_ELEMENT_ARRAY_BUFFER: |
| 242 | return true; |
| 243 | |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 244 | case GL_PIXEL_PACK_BUFFER: |
| 245 | case GL_PIXEL_UNPACK_BUFFER: |
Geoff Lang | e4de307 | 2015-09-02 11:01:32 -0400 | [diff] [blame] | 246 | return (context->getExtensions().pixelBufferObject || context->getClientVersion() >= 3); |
Shannon Woods | 158c438 | 2014-05-06 13:00:07 -0400 | [diff] [blame] | 247 | |
Shannon Woods | b380174 | 2014-03-27 14:59:19 -0400 | [diff] [blame] | 248 | case GL_COPY_READ_BUFFER: |
| 249 | case GL_COPY_WRITE_BUFFER: |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 250 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 251 | case GL_UNIFORM_BUFFER: |
| 252 | return (context->getClientVersion() >= 3); |
| 253 | |
| 254 | default: |
| 255 | return false; |
| 256 | } |
| 257 | } |
| 258 | |
Jamie Madill | 70656a6 | 2014-03-05 15:01:26 -0500 | [diff] [blame] | 259 | bool ValidBufferParameter(const Context *context, GLenum pname) |
| 260 | { |
Geoff Lang | cc6f55d | 2015-03-20 13:01:02 -0400 | [diff] [blame] | 261 | const Extensions &extensions = context->getExtensions(); |
| 262 | |
Jamie Madill | 70656a6 | 2014-03-05 15:01:26 -0500 | [diff] [blame] | 263 | switch (pname) |
| 264 | { |
| 265 | case GL_BUFFER_USAGE: |
| 266 | case GL_BUFFER_SIZE: |
| 267 | return true; |
| 268 | |
Geoff Lang | cc6f55d | 2015-03-20 13:01:02 -0400 | [diff] [blame] | 269 | case GL_BUFFER_ACCESS_OES: |
| 270 | return extensions.mapBuffer; |
| 271 | |
| 272 | case GL_BUFFER_MAPPED: |
| 273 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 274 | return (context->getClientVersion() >= 3) || extensions.mapBuffer || extensions.mapBufferRange; |
| 275 | |
Jamie Madill | 70656a6 | 2014-03-05 15:01:26 -0500 | [diff] [blame] | 276 | // GL_BUFFER_MAP_POINTER is a special case, and may only be |
| 277 | // queried with GetBufferPointerv |
| 278 | case GL_BUFFER_ACCESS_FLAGS: |
Jamie Madill | 70656a6 | 2014-03-05 15:01:26 -0500 | [diff] [blame] | 279 | case GL_BUFFER_MAP_OFFSET: |
| 280 | case GL_BUFFER_MAP_LENGTH: |
Geoff Lang | cc6f55d | 2015-03-20 13:01:02 -0400 | [diff] [blame] | 281 | return (context->getClientVersion() >= 3) || extensions.mapBufferRange; |
Jamie Madill | 70656a6 | 2014-03-05 15:01:26 -0500 | [diff] [blame] | 282 | |
| 283 | default: |
| 284 | return false; |
| 285 | } |
| 286 | } |
| 287 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 288 | bool ValidMipLevel(const ValidationContext *context, GLenum target, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 289 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 290 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 291 | size_t maxDimension = 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 292 | switch (target) |
| 293 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 294 | case GL_TEXTURE_2D: |
| 295 | maxDimension = caps.max2DTextureSize; |
| 296 | break; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 297 | case GL_TEXTURE_CUBE_MAP: |
| 298 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 299 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 300 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 301 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 302 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 303 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 304 | maxDimension = caps.maxCubeMapTextureSize; |
| 305 | break; |
| 306 | case GL_TEXTURE_3D: |
| 307 | maxDimension = caps.max3DTextureSize; |
| 308 | break; |
| 309 | case GL_TEXTURE_2D_ARRAY: |
| 310 | maxDimension = caps.max2DTextureSize; |
| 311 | break; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 312 | default: UNREACHABLE(); |
| 313 | } |
| 314 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 315 | return level <= gl::log2(static_cast<int>(maxDimension)); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 318 | bool ValidImageSizeParameters(const Context *context, |
| 319 | GLenum target, |
| 320 | GLint level, |
| 321 | GLsizei width, |
| 322 | GLsizei height, |
| 323 | GLsizei depth, |
| 324 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 325 | { |
| 326 | if (level < 0 || width < 0 || height < 0 || depth < 0) |
| 327 | { |
| 328 | return false; |
| 329 | } |
| 330 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 331 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 332 | // as long as the destination texture is POT. |
| 333 | if (!isSubImage && !context->getExtensions().textureNPOT && |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 334 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 335 | { |
| 336 | return false; |
| 337 | } |
| 338 | |
| 339 | if (!ValidMipLevel(context, target, level)) |
| 340 | { |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 347 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 348 | { |
| 349 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 350 | // the compressed block size. |
| 351 | switch (internalFormat) |
| 352 | { |
| 353 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 354 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 355 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 356 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 357 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 358 | return true; |
| 359 | |
| 360 | default: |
| 361 | return false; |
| 362 | } |
| 363 | } |
| 364 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 365 | bool ValidCompressedImageSize(const ValidationContext *context, |
| 366 | GLenum internalFormat, |
| 367 | GLsizei width, |
| 368 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 369 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 370 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 371 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 372 | { |
| 373 | return false; |
| 374 | } |
| 375 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 376 | if (width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 377 | { |
| 378 | return false; |
| 379 | } |
| 380 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 381 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 382 | { |
| 383 | if ((static_cast<GLuint>(width) > formatInfo.compressedBlockWidth && |
| 384 | width % formatInfo.compressedBlockWidth != 0) || |
| 385 | (static_cast<GLuint>(height) > formatInfo.compressedBlockHeight && |
| 386 | height % formatInfo.compressedBlockHeight != 0)) |
| 387 | { |
| 388 | return false; |
| 389 | } |
| 390 | } |
| 391 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 392 | return true; |
| 393 | } |
| 394 | |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 395 | bool ValidQueryType(const Context *context, GLenum queryType) |
| 396 | { |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 397 | static_assert(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT, "GL extension enums not equal."); |
| 398 | static_assert(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, "GL extension enums not equal."); |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 399 | |
| 400 | switch (queryType) |
| 401 | { |
| 402 | case GL_ANY_SAMPLES_PASSED: |
| 403 | case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: |
| 404 | return true; |
| 405 | case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: |
| 406 | return (context->getClientVersion() >= 3); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 407 | case GL_TIME_ELAPSED_EXT: |
| 408 | return context->getExtensions().disjointTimerQuery; |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 409 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
| 410 | return context->getExtensions().syncQuery; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 411 | default: |
| 412 | return false; |
| 413 | } |
| 414 | } |
| 415 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 416 | Program *GetValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 417 | { |
| 418 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the |
| 419 | // error INVALID_VALUE if the provided name is not the name of either a shader or program object and |
| 420 | // INVALID_OPERATION if the provided name identifies an object that is not the expected type." |
| 421 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 422 | Program *validProgram = context->getProgram(id); |
| 423 | |
| 424 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 425 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 426 | if (context->getShader(id)) |
| 427 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 428 | context->handleError( |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 429 | Error(GL_INVALID_OPERATION, "Expected a program name, but found a shader name")); |
| 430 | } |
| 431 | else |
| 432 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 433 | context->handleError(Error(GL_INVALID_VALUE, "Program name is not valid")); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 434 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 435 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 436 | |
| 437 | return validProgram; |
| 438 | } |
| 439 | |
| 440 | Shader *GetValidShader(Context *context, GLuint id) |
| 441 | { |
| 442 | // See ValidProgram for spec details. |
| 443 | |
| 444 | Shader *validShader = context->getShader(id); |
| 445 | |
| 446 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 447 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 448 | if (context->getProgram(id)) |
| 449 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 450 | context->handleError( |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 451 | Error(GL_INVALID_OPERATION, "Expected a shader name, but found a program name")); |
| 452 | } |
| 453 | else |
| 454 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 455 | context->handleError(Error(GL_INVALID_VALUE, "Shader name is invalid")); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 456 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 457 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 458 | |
| 459 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 460 | } |
| 461 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 462 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 463 | { |
| 464 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 465 | { |
| 466 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
| 467 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 468 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 469 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 470 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 471 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | else |
| 475 | { |
| 476 | switch (attachment) |
| 477 | { |
| 478 | case GL_DEPTH_ATTACHMENT: |
| 479 | case GL_STENCIL_ATTACHMENT: |
| 480 | break; |
| 481 | |
| 482 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 483 | if (context->getClientVersion() < 3) |
| 484 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 485 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 486 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 487 | } |
| 488 | break; |
| 489 | |
| 490 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 491 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 492 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | return true; |
| 497 | } |
| 498 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 499 | bool ValidateRenderbufferStorageParametersBase(gl::Context *context, GLenum target, GLsizei samples, |
| 500 | GLenum internalformat, GLsizei width, GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 501 | { |
| 502 | switch (target) |
| 503 | { |
| 504 | case GL_RENDERBUFFER: |
| 505 | break; |
| 506 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 507 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 508 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | if (width < 0 || height < 0 || samples < 0) |
| 512 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 513 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 514 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 515 | } |
| 516 | |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 517 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 518 | if (!formatCaps.renderable) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 519 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 520 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 521 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 525 | // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 526 | // only sized internal formats. |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 527 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 528 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 529 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 530 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 531 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 532 | } |
| 533 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 534 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 535 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 536 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 537 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 538 | } |
| 539 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 540 | GLuint handle = context->getState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 541 | if (handle == 0) |
| 542 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 543 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 544 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | return true; |
| 548 | } |
| 549 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 550 | bool ValidateRenderbufferStorageParametersANGLE(gl::Context *context, GLenum target, GLsizei samples, |
| 551 | GLenum internalformat, GLsizei width, GLsizei height) |
| 552 | { |
Austin Kinross | d2cf3ad | 2015-01-07 14:00:30 -0800 | [diff] [blame] | 553 | ASSERT(samples == 0 || context->getExtensions().framebufferMultisample); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 554 | |
| 555 | // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal |
Geoff Lang | def624b | 2015-04-13 10:46:56 -0400 | [diff] [blame] | 556 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 557 | // generated. |
Geoff Lang | def624b | 2015-04-13 10:46:56 -0400 | [diff] [blame] | 558 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 559 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 560 | context->handleError(Error(GL_INVALID_VALUE)); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 561 | return false; |
| 562 | } |
| 563 | |
| 564 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 565 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 566 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 567 | // The TextureCaps::getMaxSamples method is only guarenteed to be valid when the context is ES3. |
| 568 | if (context->getClientVersion() >= 3) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 569 | { |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 570 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 571 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 572 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 573 | context->handleError(Error(GL_OUT_OF_MEMORY)); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 574 | return false; |
| 575 | } |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, height); |
| 579 | } |
| 580 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 581 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment, |
| 582 | GLenum renderbuffertarget, GLuint renderbuffer) |
| 583 | { |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 584 | if (!ValidFramebufferTarget(target)) |
| 585 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 586 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 587 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 590 | gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 591 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 592 | ASSERT(framebuffer); |
| 593 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 594 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 595 | context->handleError( |
| 596 | Error(GL_INVALID_OPERATION, "Cannot change default FBO's attachments")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 597 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 598 | } |
| 599 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 600 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 601 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 602 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 603 | } |
| 604 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 605 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 606 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 607 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 608 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 609 | if (renderbuffer != 0) |
| 610 | { |
| 611 | if (!context->getRenderbuffer(renderbuffer)) |
| 612 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 613 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 614 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 618 | return true; |
| 619 | } |
| 620 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 621 | bool ValidateBlitFramebufferParameters(gl::Context *context, |
| 622 | GLint srcX0, |
| 623 | GLint srcY0, |
| 624 | GLint srcX1, |
| 625 | GLint srcY1, |
| 626 | GLint dstX0, |
| 627 | GLint dstY0, |
| 628 | GLint dstX1, |
| 629 | GLint dstY1, |
| 630 | GLbitfield mask, |
| 631 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 632 | { |
| 633 | switch (filter) |
| 634 | { |
| 635 | case GL_NEAREST: |
| 636 | break; |
| 637 | case GL_LINEAR: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 638 | break; |
| 639 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 640 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 641 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 645 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 646 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 647 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | if (mask == 0) |
| 651 | { |
| 652 | // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no |
| 653 | // buffers are copied. |
| 654 | return false; |
| 655 | } |
| 656 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 657 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 658 | // color buffer, leaving only nearest being unfiltered from above |
| 659 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 660 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 661 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 662 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 663 | } |
| 664 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 665 | if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 666 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 667 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 668 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 669 | } |
| 670 | |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 671 | const gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 672 | const gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 673 | |
| 674 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 675 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 676 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 677 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 678 | } |
| 679 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 680 | if (!readFramebuffer->checkStatus(context->getData())) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 681 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 682 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 683 | return false; |
| 684 | } |
| 685 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 686 | if (!drawFramebuffer->checkStatus(context->getData())) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 687 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 688 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 689 | return false; |
| 690 | } |
| 691 | |
| 692 | if (drawFramebuffer->getSamples(context->getData()) != 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 693 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 694 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 695 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 696 | } |
| 697 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 698 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 699 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 700 | if (mask & GL_COLOR_BUFFER_BIT) |
| 701 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 702 | const gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 703 | const gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer(); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 704 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 705 | |
| 706 | if (readColorBuffer && drawColorBuffer) |
| 707 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 708 | GLenum readInternalFormat = readColorBuffer->getInternalFormat(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 709 | const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 710 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 711 | for (size_t drawbufferIdx = 0; |
| 712 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 713 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 714 | const FramebufferAttachment *attachment = |
| 715 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 716 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 717 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 718 | GLenum drawInternalFormat = attachment->getInternalFormat(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 719 | const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 720 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 721 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 722 | // 1) If the read buffer is fixed point format, the draw buffer must be as well |
| 723 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well |
| 724 | // 3) If the read buffer is a signed integer format, the draw buffer must be as well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 725 | // Changes with EXT_color_buffer_float: |
| 726 | // Case 1) is changed to fixed point OR floating point |
| 727 | GLenum readComponentType = readFormatInfo.componentType; |
| 728 | GLenum drawComponentType = drawFormatInfo.componentType; |
| 729 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
| 730 | readComponentType == GL_SIGNED_NORMALIZED); |
| 731 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
| 732 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 733 | |
| 734 | if (extensions.colorBufferFloat) |
| 735 | { |
| 736 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 737 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 738 | |
| 739 | if (readFixedOrFloat != drawFixedOrFloat) |
| 740 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 741 | context->handleError(Error(GL_INVALID_OPERATION, |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 742 | "If the read buffer contains fixed-point or " |
| 743 | "floating-point values, the draw buffer " |
| 744 | "must as well.")); |
| 745 | return false; |
| 746 | } |
| 747 | } |
| 748 | else if (readFixedPoint != drawFixedPoint) |
| 749 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 750 | context->handleError(Error(GL_INVALID_OPERATION, |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 751 | "If the read buffer contains fixed-point " |
| 752 | "values, the draw buffer must as well.")); |
| 753 | return false; |
| 754 | } |
| 755 | |
| 756 | if (readComponentType == GL_UNSIGNED_INT && |
| 757 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 758 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 759 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 760 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 761 | } |
| 762 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 763 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 764 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 765 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 766 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 769 | if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 770 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 771 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 772 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 777 | if ((readFormatInfo.componentType == GL_INT || readFormatInfo.componentType == GL_UNSIGNED_INT) && filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 778 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 779 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 780 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 781 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 785 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 786 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 787 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 788 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 789 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 790 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 791 | const gl::FramebufferAttachment *readBuffer = readFramebuffer->getAttachment(attachments[i]); |
| 792 | const gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getAttachment(attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 793 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 794 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 795 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 796 | if (readBuffer->getInternalFormat() != drawBuffer->getInternalFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 797 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 798 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 799 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 800 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 801 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 802 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 803 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 804 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 805 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | return true; |
| 812 | } |
| 813 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 814 | bool ValidateGetVertexAttribParameters(Context *context, GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 815 | { |
| 816 | switch (pname) |
| 817 | { |
| 818 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 819 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 820 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 821 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 822 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 823 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 824 | case GL_CURRENT_VERTEX_ATTRIB: |
| 825 | return true; |
| 826 | |
| 827 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 828 | // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses |
| 829 | // the same constant. |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 830 | static_assert(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 831 | "ANGLE extension enums not equal to GL enums."); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 832 | return true; |
| 833 | |
| 834 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 835 | if (context->getClientVersion() < 3) |
| 836 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 837 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 838 | return false; |
| 839 | } |
| 840 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 841 | |
| 842 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 843 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 844 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 848 | bool ValidateTexParamParameters(gl::Context *context, GLenum target, GLenum pname, GLint param) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 849 | { |
| 850 | switch (pname) |
| 851 | { |
| 852 | case GL_TEXTURE_WRAP_R: |
| 853 | case GL_TEXTURE_SWIZZLE_R: |
| 854 | case GL_TEXTURE_SWIZZLE_G: |
| 855 | case GL_TEXTURE_SWIZZLE_B: |
| 856 | case GL_TEXTURE_SWIZZLE_A: |
| 857 | case GL_TEXTURE_BASE_LEVEL: |
| 858 | case GL_TEXTURE_MAX_LEVEL: |
| 859 | case GL_TEXTURE_COMPARE_MODE: |
| 860 | case GL_TEXTURE_COMPARE_FUNC: |
| 861 | case GL_TEXTURE_MIN_LOD: |
| 862 | case GL_TEXTURE_MAX_LOD: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 863 | if (context->getClientVersion() < 3) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 864 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 865 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 866 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 867 | } |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 868 | if (target == GL_TEXTURE_EXTERNAL_OES && !context->getExtensions().eglImageExternalEssl3) |
| 869 | { |
| 870 | context->handleError(Error(GL_INVALID_ENUM, |
| 871 | "ES3 texture parameters are not available without " |
| 872 | "GL_OES_EGL_image_external_essl3.")); |
| 873 | return false; |
| 874 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | default: break; |
| 878 | } |
| 879 | |
| 880 | switch (pname) |
| 881 | { |
| 882 | case GL_TEXTURE_WRAP_S: |
| 883 | case GL_TEXTURE_WRAP_T: |
| 884 | case GL_TEXTURE_WRAP_R: |
| 885 | switch (param) |
| 886 | { |
Corentin Wallez | 9670b03 | 2016-04-29 09:47:47 +0000 | [diff] [blame] | 887 | case GL_CLAMP_TO_EDGE: |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 888 | return true; |
| 889 | case GL_REPEAT: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 890 | case GL_MIRRORED_REPEAT: |
Olli Etuaho | bd32909 | 2016-04-29 12:51:42 +0300 | [diff] [blame] | 891 | if (target == GL_TEXTURE_EXTERNAL_OES) |
| 892 | { |
| 893 | // OES_EGL_image_external specifies this error. |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 894 | context->handleError(Error( |
Olli Etuaho | bd32909 | 2016-04-29 12:51:42 +0300 | [diff] [blame] | 895 | GL_INVALID_ENUM, "external textures only support CLAMP_TO_EDGE wrap mode")); |
| 896 | return false; |
| 897 | } |
| 898 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 899 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 900 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 901 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | case GL_TEXTURE_MIN_FILTER: |
| 905 | switch (param) |
| 906 | { |
| 907 | case GL_NEAREST: |
| 908 | case GL_LINEAR: |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 909 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 910 | case GL_NEAREST_MIPMAP_NEAREST: |
| 911 | case GL_LINEAR_MIPMAP_NEAREST: |
| 912 | case GL_NEAREST_MIPMAP_LINEAR: |
| 913 | case GL_LINEAR_MIPMAP_LINEAR: |
Olli Etuaho | bd32909 | 2016-04-29 12:51:42 +0300 | [diff] [blame] | 914 | if (target == GL_TEXTURE_EXTERNAL_OES) |
| 915 | { |
| 916 | // OES_EGL_image_external specifies this error. |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 917 | context->handleError( |
Olli Etuaho | bd32909 | 2016-04-29 12:51:42 +0300 | [diff] [blame] | 918 | Error(GL_INVALID_ENUM, |
| 919 | "external textures only support NEAREST and LINEAR filtering")); |
| 920 | return false; |
| 921 | } |
| 922 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 923 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 924 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 925 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 926 | } |
| 927 | break; |
| 928 | |
| 929 | case GL_TEXTURE_MAG_FILTER: |
| 930 | switch (param) |
| 931 | { |
| 932 | case GL_NEAREST: |
| 933 | case GL_LINEAR: |
| 934 | return true; |
| 935 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 936 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 937 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 938 | } |
| 939 | break; |
| 940 | |
| 941 | case GL_TEXTURE_USAGE_ANGLE: |
| 942 | switch (param) |
| 943 | { |
| 944 | case GL_NONE: |
| 945 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 946 | return true; |
| 947 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 948 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 949 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 950 | } |
| 951 | break; |
| 952 | |
| 953 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 954 | if (!context->getExtensions().textureFilterAnisotropic) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 955 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 956 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 957 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | // we assume the parameter passed to this validation method is truncated, not rounded |
| 961 | if (param < 1) |
| 962 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 963 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 964 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 965 | } |
| 966 | return true; |
| 967 | |
| 968 | case GL_TEXTURE_MIN_LOD: |
| 969 | case GL_TEXTURE_MAX_LOD: |
| 970 | // any value is permissible |
| 971 | return true; |
| 972 | |
| 973 | case GL_TEXTURE_COMPARE_MODE: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 974 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 975 | switch (param) |
| 976 | { |
| 977 | case GL_NONE: |
| 978 | case GL_COMPARE_REF_TO_TEXTURE: |
| 979 | return true; |
| 980 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 981 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 982 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 983 | } |
| 984 | break; |
| 985 | |
| 986 | case GL_TEXTURE_COMPARE_FUNC: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 987 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 988 | switch (param) |
| 989 | { |
| 990 | case GL_LEQUAL: |
| 991 | case GL_GEQUAL: |
| 992 | case GL_LESS: |
| 993 | case GL_GREATER: |
| 994 | case GL_EQUAL: |
| 995 | case GL_NOTEQUAL: |
| 996 | case GL_ALWAYS: |
| 997 | case GL_NEVER: |
| 998 | return true; |
| 999 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1000 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1001 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1002 | } |
| 1003 | break; |
| 1004 | |
| 1005 | case GL_TEXTURE_SWIZZLE_R: |
| 1006 | case GL_TEXTURE_SWIZZLE_G: |
| 1007 | case GL_TEXTURE_SWIZZLE_B: |
| 1008 | case GL_TEXTURE_SWIZZLE_A: |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 1009 | switch (param) |
| 1010 | { |
| 1011 | case GL_RED: |
| 1012 | case GL_GREEN: |
| 1013 | case GL_BLUE: |
| 1014 | case GL_ALPHA: |
| 1015 | case GL_ZERO: |
| 1016 | case GL_ONE: |
| 1017 | return true; |
| 1018 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1019 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1020 | return false; |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 1021 | } |
| 1022 | break; |
| 1023 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1024 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 1025 | if (param < 0) |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1026 | { |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 1027 | context->handleError(Error(GL_INVALID_VALUE)); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1028 | return false; |
| 1029 | } |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 1030 | if (target == GL_TEXTURE_EXTERNAL_OES && param != 0) |
| 1031 | { |
| 1032 | context->handleError( |
| 1033 | Error(GL_INVALID_OPERATION, "Base level must be 0 for external textures.")); |
| 1034 | return false; |
| 1035 | } |
| 1036 | return true; |
| 1037 | |
| 1038 | case GL_TEXTURE_MAX_LEVEL: |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1039 | if (param < 0) |
| 1040 | { |
| 1041 | context->handleError(Error(GL_INVALID_VALUE)); |
| 1042 | return false; |
| 1043 | } |
| 1044 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1045 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1046 | context->handleError(Error(GL_INVALID_ENUM)); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1047 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1051 | bool ValidateSamplerObjectParameter(gl::Context *context, GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1052 | { |
| 1053 | switch (pname) |
| 1054 | { |
| 1055 | case GL_TEXTURE_MIN_FILTER: |
| 1056 | case GL_TEXTURE_MAG_FILTER: |
| 1057 | case GL_TEXTURE_WRAP_S: |
| 1058 | case GL_TEXTURE_WRAP_T: |
| 1059 | case GL_TEXTURE_WRAP_R: |
| 1060 | case GL_TEXTURE_MIN_LOD: |
| 1061 | case GL_TEXTURE_MAX_LOD: |
| 1062 | case GL_TEXTURE_COMPARE_MODE: |
| 1063 | case GL_TEXTURE_COMPARE_FUNC: |
| 1064 | return true; |
| 1065 | |
| 1066 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1067 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1068 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1072 | bool ValidateReadPixels(Context *context, |
| 1073 | GLint x, |
| 1074 | GLint y, |
| 1075 | GLsizei width, |
| 1076 | GLsizei height, |
| 1077 | GLenum format, |
| 1078 | GLenum type, |
| 1079 | GLvoid *pixels) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1080 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1081 | if (width < 0 || height < 0) |
| 1082 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1083 | context->handleError(Error(GL_INVALID_VALUE, "width and height must be positive")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1084 | return false; |
| 1085 | } |
| 1086 | |
| 1087 | Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1088 | ASSERT(framebuffer); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1089 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1090 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1091 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1092 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1093 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1094 | } |
| 1095 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1096 | if (context->getState().getReadFramebuffer()->id() != 0 && |
| 1097 | framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1098 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1099 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1100 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1103 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 1104 | if (!readBuffer) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1105 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1106 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1107 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1110 | GLenum currentFormat = framebuffer->getImplementationColorReadFormat(); |
| 1111 | GLenum currentType = framebuffer->getImplementationColorReadType(); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 1112 | GLenum currentInternalFormat = readBuffer->getInternalFormat(); |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 1113 | GLuint clientVersion = context->getClientVersion(); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1114 | |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1115 | bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) : |
| 1116 | ValidES3ReadFormatType(context, currentInternalFormat, format, type); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1117 | |
| 1118 | if (!(currentFormat == format && currentType == type) && !validReadFormat) |
| 1119 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1120 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1121 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1122 | } |
| 1123 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1124 | return true; |
| 1125 | } |
| 1126 | |
| 1127 | bool ValidateReadnPixelsEXT(Context *context, |
| 1128 | GLint x, |
| 1129 | GLint y, |
| 1130 | GLsizei width, |
| 1131 | GLsizei height, |
| 1132 | GLenum format, |
| 1133 | GLenum type, |
| 1134 | GLsizei bufSize, |
| 1135 | GLvoid *pixels) |
| 1136 | { |
| 1137 | if (bufSize < 0) |
| 1138 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1139 | context->handleError(Error(GL_INVALID_VALUE, "bufSize must be a positive number")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1140 | return false; |
| 1141 | } |
| 1142 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1143 | GLenum sizedInternalFormat = GetSizedInternalFormat(format, type); |
| 1144 | const InternalFormat &sizedFormatInfo = GetInternalFormatInfo(sizedInternalFormat); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1145 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1146 | auto outputPitchOrErr = |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1147 | sizedFormatInfo.computeRowPitch(type, width, context->getState().getPackAlignment(), |
| 1148 | context->getState().getPackRowLength()); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1149 | |
| 1150 | if (outputPitchOrErr.isError()) |
| 1151 | { |
| 1152 | context->handleError(outputPitchOrErr.getError()); |
| 1153 | return false; |
| 1154 | } |
| 1155 | |
| 1156 | CheckedNumeric<GLuint> checkedOutputPitch(outputPitchOrErr.getResult()); |
| 1157 | auto checkedRequiredSize = checkedOutputPitch * height; |
| 1158 | if (!checkedRequiredSize.IsValid()) |
| 1159 | { |
| 1160 | context->handleError(Error(GL_INVALID_OPERATION, "Unsigned multiplication overflow.")); |
| 1161 | return false; |
| 1162 | } |
| 1163 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1164 | // sized query sanity check |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1165 | if (checkedRequiredSize.ValueOrDie() > static_cast<GLuint>(bufSize)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1166 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1167 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1168 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1169 | } |
| 1170 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1171 | return ValidateReadPixels(context, x, y, width, height, format, type, pixels); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1172 | } |
| 1173 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1174 | bool ValidateGenQueriesEXT(gl::Context *context, GLsizei n) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1175 | { |
| 1176 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1177 | !context->getExtensions().disjointTimerQuery) |
| 1178 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1179 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1180 | return false; |
| 1181 | } |
| 1182 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1183 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1184 | } |
| 1185 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1186 | bool ValidateDeleteQueriesEXT(gl::Context *context, GLsizei n) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1187 | { |
| 1188 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1189 | !context->getExtensions().disjointTimerQuery) |
| 1190 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1191 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1192 | return false; |
| 1193 | } |
| 1194 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1195 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | bool ValidateBeginQueryBase(gl::Context *context, GLenum target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1199 | { |
| 1200 | if (!ValidQueryType(context, target)) |
| 1201 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1202 | context->handleError(Error(GL_INVALID_ENUM, "Invalid query target")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1203 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | if (id == 0) |
| 1207 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1208 | context->handleError(Error(GL_INVALID_OPERATION, "Query id is 0")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1209 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1213 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1214 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1215 | // the active query for either target is non-zero), if <id> is the name of an |
| 1216 | // existing query object whose type does not match <target>, or if <id> is the |
| 1217 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1218 | // generated. |
| 1219 | |
| 1220 | // Ensure no other queries are active |
| 1221 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1222 | // separately that: |
| 1223 | // a) The query ID passed is not the current active query for any target/type |
| 1224 | // b) There are no active queries for the requested target (and in the case |
| 1225 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1226 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1227 | |
Corentin Wallez | e71ea19 | 2016-04-19 13:16:37 -0400 | [diff] [blame] | 1228 | if (context->getState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1229 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1230 | context->handleError(Error(GL_INVALID_OPERATION, "Other query is active")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1231 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | Query *queryObject = context->getQuery(id, true, target); |
| 1235 | |
| 1236 | // check that name was obtained with glGenQueries |
| 1237 | if (!queryObject) |
| 1238 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1239 | context->handleError(Error(GL_INVALID_OPERATION, "Invalid query id")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1240 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | // check for type mismatch |
| 1244 | if (queryObject->getType() != target) |
| 1245 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1246 | context->handleError(Error(GL_INVALID_OPERATION, "Query type does not match target")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1247 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | return true; |
| 1251 | } |
| 1252 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1253 | bool ValidateBeginQueryEXT(gl::Context *context, GLenum target, GLuint id) |
| 1254 | { |
| 1255 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1256 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1257 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1258 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1259 | return false; |
| 1260 | } |
| 1261 | |
| 1262 | return ValidateBeginQueryBase(context, target, id); |
| 1263 | } |
| 1264 | |
| 1265 | bool ValidateEndQueryBase(gl::Context *context, GLenum target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1266 | { |
| 1267 | if (!ValidQueryType(context, target)) |
| 1268 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1269 | context->handleError(Error(GL_INVALID_ENUM, "Invalid query target")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1270 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1271 | } |
| 1272 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1273 | const Query *queryObject = context->getState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1274 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1275 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1276 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1277 | context->handleError(Error(GL_INVALID_OPERATION, "Query target not active")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1278 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1279 | } |
| 1280 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1281 | return true; |
| 1282 | } |
| 1283 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1284 | bool ValidateEndQueryEXT(gl::Context *context, GLenum target) |
| 1285 | { |
| 1286 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1287 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1288 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1289 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | return ValidateEndQueryBase(context, target); |
| 1294 | } |
| 1295 | |
| 1296 | bool ValidateQueryCounterEXT(Context *context, GLuint id, GLenum target) |
| 1297 | { |
| 1298 | if (!context->getExtensions().disjointTimerQuery) |
| 1299 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1300 | context->handleError(Error(GL_INVALID_OPERATION, "Disjoint timer query not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1301 | return false; |
| 1302 | } |
| 1303 | |
| 1304 | if (target != GL_TIMESTAMP_EXT) |
| 1305 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1306 | context->handleError(Error(GL_INVALID_ENUM, "Invalid query target")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1307 | return false; |
| 1308 | } |
| 1309 | |
| 1310 | Query *queryObject = context->getQuery(id, true, target); |
| 1311 | if (queryObject == nullptr) |
| 1312 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1313 | context->handleError(Error(GL_INVALID_OPERATION, "Invalid query id")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1314 | return false; |
| 1315 | } |
| 1316 | |
| 1317 | if (context->getState().isQueryActive(queryObject)) |
| 1318 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1319 | context->handleError(Error(GL_INVALID_OPERATION, "Query is active")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1320 | return false; |
| 1321 | } |
| 1322 | |
| 1323 | return true; |
| 1324 | } |
| 1325 | |
| 1326 | bool ValidateGetQueryivBase(Context *context, GLenum target, GLenum pname) |
| 1327 | { |
| 1328 | if (!ValidQueryType(context, target) && target != GL_TIMESTAMP_EXT) |
| 1329 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1330 | context->handleError(Error(GL_INVALID_ENUM, "Invalid query type")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1331 | return false; |
| 1332 | } |
| 1333 | |
| 1334 | switch (pname) |
| 1335 | { |
| 1336 | case GL_CURRENT_QUERY_EXT: |
| 1337 | if (target == GL_TIMESTAMP_EXT) |
| 1338 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1339 | context->handleError( |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1340 | Error(GL_INVALID_ENUM, "Cannot use current query for timestamp")); |
| 1341 | return false; |
| 1342 | } |
| 1343 | break; |
| 1344 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1345 | if (!context->getExtensions().disjointTimerQuery || |
| 1346 | (target != GL_TIMESTAMP_EXT && target != GL_TIME_ELAPSED_EXT)) |
| 1347 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1348 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1349 | return false; |
| 1350 | } |
| 1351 | break; |
| 1352 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1353 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1354 | return false; |
| 1355 | } |
| 1356 | |
| 1357 | return true; |
| 1358 | } |
| 1359 | |
| 1360 | bool ValidateGetQueryivEXT(Context *context, GLenum target, GLenum pname, GLint *params) |
| 1361 | { |
| 1362 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1363 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1364 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1365 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1366 | return false; |
| 1367 | } |
| 1368 | |
| 1369 | return ValidateGetQueryivBase(context, target, pname); |
| 1370 | } |
| 1371 | |
| 1372 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname) |
| 1373 | { |
| 1374 | Query *queryObject = context->getQuery(id, false, GL_NONE); |
| 1375 | |
| 1376 | if (!queryObject) |
| 1377 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1378 | context->handleError(Error(GL_INVALID_OPERATION, "Query does not exist")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1379 | return false; |
| 1380 | } |
| 1381 | |
| 1382 | if (context->getState().isQueryActive(queryObject)) |
| 1383 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1384 | context->handleError(Error(GL_INVALID_OPERATION, "Query currently active")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1385 | return false; |
| 1386 | } |
| 1387 | |
| 1388 | switch (pname) |
| 1389 | { |
| 1390 | case GL_QUERY_RESULT_EXT: |
| 1391 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1392 | break; |
| 1393 | |
| 1394 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1395 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname enum")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1396 | return false; |
| 1397 | } |
| 1398 | |
| 1399 | return true; |
| 1400 | } |
| 1401 | |
| 1402 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1403 | { |
| 1404 | if (!context->getExtensions().disjointTimerQuery) |
| 1405 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1406 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1407 | return false; |
| 1408 | } |
| 1409 | return ValidateGetQueryObjectValueBase(context, id, pname); |
| 1410 | } |
| 1411 | |
| 1412 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1413 | { |
| 1414 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1415 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1416 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1417 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1418 | return false; |
| 1419 | } |
| 1420 | return ValidateGetQueryObjectValueBase(context, id, pname); |
| 1421 | } |
| 1422 | |
| 1423 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1424 | { |
| 1425 | if (!context->getExtensions().disjointTimerQuery) |
| 1426 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1427 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1428 | return false; |
| 1429 | } |
| 1430 | return ValidateGetQueryObjectValueBase(context, id, pname); |
| 1431 | } |
| 1432 | |
| 1433 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 1434 | { |
| 1435 | if (!context->getExtensions().disjointTimerQuery) |
| 1436 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1437 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1438 | return false; |
| 1439 | } |
| 1440 | return ValidateGetQueryObjectValueBase(context, id, pname); |
| 1441 | } |
| 1442 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1443 | static bool ValidateUniformCommonBase(gl::Context *context, |
| 1444 | GLenum targetUniformType, |
| 1445 | GLint location, |
| 1446 | GLsizei count, |
| 1447 | const LinkedUniform **uniformOut) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1448 | { |
| 1449 | if (count < 0) |
| 1450 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1451 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1452 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1453 | } |
| 1454 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1455 | gl::Program *program = context->getState().getProgram(); |
| 1456 | if (!program) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1457 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1458 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1459 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 1462 | if (program->isIgnoredUniformLocation(location)) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1463 | { |
| 1464 | // Silently ignore the uniform command |
| 1465 | return false; |
| 1466 | } |
| 1467 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1468 | if (!program->isValidUniformLocation(location)) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1469 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1470 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1471 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1472 | } |
| 1473 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1474 | const LinkedUniform &uniform = program->getUniformByLocation(location); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1475 | |
| 1476 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1477 | if (!uniform.isArray() && count > 1) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1478 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1479 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1480 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1481 | } |
| 1482 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1483 | *uniformOut = &uniform; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1484 | return true; |
| 1485 | } |
| 1486 | |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1487 | bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count) |
| 1488 | { |
| 1489 | // Check for ES3 uniform entry points |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1490 | if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1491 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1492 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1493 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1496 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1497 | if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform)) |
| 1498 | { |
| 1499 | return false; |
| 1500 | } |
| 1501 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1502 | GLenum targetBoolType = VariableBoolVectorType(uniformType); |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 1503 | bool samplerUniformCheck = (IsSamplerType(uniform->type) && uniformType == GL_INT); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1504 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 1505 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1506 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1507 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count, |
| 1514 | GLboolean transpose) |
| 1515 | { |
| 1516 | // Check for ES3 uniform entry points |
| 1517 | int rows = VariableRowCount(matrixType); |
| 1518 | int cols = VariableColumnCount(matrixType); |
| 1519 | if (rows != cols && context->getClientVersion() < 3) |
| 1520 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1521 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1522 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | if (transpose != GL_FALSE && context->getClientVersion() < 3) |
| 1526 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1527 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1528 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1529 | } |
| 1530 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1531 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1532 | if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform)) |
| 1533 | { |
| 1534 | return false; |
| 1535 | } |
| 1536 | |
| 1537 | if (uniform->type != matrixType) |
| 1538 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1539 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1540 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1544 | } |
| 1545 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1546 | bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
| 1547 | { |
| 1548 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 1549 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1550 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1551 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1552 | } |
| 1553 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 1554 | const Caps &caps = context->getCaps(); |
| 1555 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1556 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 1557 | { |
| 1558 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 1559 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 1560 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1561 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1562 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1563 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | switch (pname) |
| 1568 | { |
| 1569 | case GL_TEXTURE_BINDING_2D: |
| 1570 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1571 | case GL_TEXTURE_BINDING_3D: |
| 1572 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1573 | break; |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 1574 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 1575 | if (!context->getExtensions().eglStreamConsumerExternal) |
| 1576 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1577 | context->handleError( |
Ian Ewell | 54f8746 | 2016-03-10 13:47:21 -0500 | [diff] [blame] | 1578 | Error(GL_INVALID_ENUM, "NV_EGL_stream_consumer_external extension not enabled")); |
| 1579 | return false; |
| 1580 | } |
| 1581 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1582 | |
| 1583 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1584 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1585 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1586 | Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1587 | ASSERT(framebuffer); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1588 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1589 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1590 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1591 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1592 | } |
| 1593 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1594 | const FramebufferAttachment *attachment = framebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 1595 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1596 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1597 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1598 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1599 | } |
| 1600 | } |
| 1601 | break; |
| 1602 | |
| 1603 | default: |
| 1604 | break; |
| 1605 | } |
| 1606 | |
| 1607 | // pname is valid, but there are no parameters to return |
| 1608 | if (numParams == 0) |
| 1609 | { |
| 1610 | return false; |
| 1611 | } |
| 1612 | |
| 1613 | return true; |
| 1614 | } |
| 1615 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1616 | bool ValidateCopyTexImageParametersBase(ValidationContext *context, |
| 1617 | GLenum target, |
| 1618 | GLint level, |
| 1619 | GLenum internalformat, |
| 1620 | bool isSubImage, |
| 1621 | GLint xoffset, |
| 1622 | GLint yoffset, |
| 1623 | GLint zoffset, |
| 1624 | GLint x, |
| 1625 | GLint y, |
| 1626 | GLsizei width, |
| 1627 | GLsizei height, |
| 1628 | GLint border, |
| 1629 | GLenum *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1630 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1631 | if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0) |
| 1632 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1633 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1634 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1638 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1639 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1640 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | if (border != 0) |
| 1644 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1645 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1646 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | if (!ValidMipLevel(context, target, level)) |
| 1650 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1651 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1652 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1653 | } |
| 1654 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1655 | const gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1656 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1657 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1658 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1659 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1662 | const auto &state = context->getState(); |
| 1663 | if (state.getReadFramebuffer()->id() != 0 && framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1664 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1665 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1666 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1667 | } |
| 1668 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1669 | const gl::Caps &caps = context->getCaps(); |
| 1670 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1671 | GLuint maxDimension = 0; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1672 | switch (target) |
| 1673 | { |
| 1674 | case GL_TEXTURE_2D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1675 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1676 | break; |
| 1677 | |
| 1678 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1679 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1680 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1681 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1682 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1683 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1684 | maxDimension = caps.maxCubeMapTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1685 | break; |
| 1686 | |
| 1687 | case GL_TEXTURE_2D_ARRAY: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1688 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1689 | break; |
| 1690 | |
| 1691 | case GL_TEXTURE_3D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1692 | maxDimension = caps.max3DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1693 | break; |
| 1694 | |
| 1695 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1696 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1697 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1700 | gl::Texture *texture = |
| 1701 | state.getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1702 | if (!texture) |
| 1703 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1704 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1705 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1706 | } |
| 1707 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1708 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1709 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1710 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1711 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1714 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1715 | |
| 1716 | if (formatInfo.depthBits > 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1717 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1718 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1719 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1720 | } |
| 1721 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1722 | if (formatInfo.compressed && !ValidCompressedImageSize(context, internalformat, width, height)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1723 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1724 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1725 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | if (isSubImage) |
| 1729 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1730 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1731 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 1732 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1733 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1734 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1735 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1736 | } |
| 1737 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1738 | else |
| 1739 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1740 | if (IsCubeMapTextureTarget(target) && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1741 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1742 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1743 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1744 | } |
| 1745 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1746 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1747 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1748 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1749 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | int maxLevelDimension = (maxDimension >> level); |
| 1753 | if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension) |
| 1754 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1755 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1756 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1757 | } |
| 1758 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1759 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1760 | *textureFormatOut = texture->getInternalFormat(target, level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1761 | return true; |
| 1762 | } |
| 1763 | |
Jamie Madill | f25855c | 2015-11-03 11:06:18 -0500 | [diff] [blame] | 1764 | static bool ValidateDrawBase(ValidationContext *context, |
| 1765 | GLenum mode, |
| 1766 | GLsizei count, |
| 1767 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1768 | { |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1769 | switch (mode) |
| 1770 | { |
| 1771 | case GL_POINTS: |
| 1772 | case GL_LINES: |
| 1773 | case GL_LINE_LOOP: |
| 1774 | case GL_LINE_STRIP: |
| 1775 | case GL_TRIANGLES: |
| 1776 | case GL_TRIANGLE_STRIP: |
| 1777 | case GL_TRIANGLE_FAN: |
| 1778 | break; |
| 1779 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1780 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1781 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1782 | } |
| 1783 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1784 | if (count < 0) |
| 1785 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1786 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1787 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1788 | } |
| 1789 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1790 | const State &state = context->getState(); |
| 1791 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1792 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1793 | if (state.hasMappedBuffer(GL_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1794 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1795 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1796 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1797 | } |
| 1798 | |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 1799 | if (context->getLimitations().noSeparateStencilRefsAndMasks) |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1800 | { |
Jinyoung Hur | 85769f0 | 2015-10-20 17:08:44 -0400 | [diff] [blame] | 1801 | const Framebuffer *framebuffer = context->getState().getDrawFramebuffer(); |
| 1802 | const FramebufferAttachment *stencilBuffer = framebuffer->getStencilbuffer(); |
| 1803 | GLuint stencilBits = stencilBuffer ? stencilBuffer->getStencilSize() : 0; |
| 1804 | GLuint minimumRequiredStencilMask = (1 << stencilBits) - 1; |
| 1805 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 1806 | if ((depthStencilState.stencilWritemask & minimumRequiredStencilMask) != |
| 1807 | (depthStencilState.stencilBackWritemask & minimumRequiredStencilMask) || |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 1808 | state.getStencilRef() != state.getStencilBackRef() || |
Jinyoung Hur | 85769f0 | 2015-10-20 17:08:44 -0400 | [diff] [blame] | 1809 | (depthStencilState.stencilMask & minimumRequiredStencilMask) != |
| 1810 | (depthStencilState.stencilBackMask & minimumRequiredStencilMask)) |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 1811 | { |
| 1812 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 1813 | // Section 6.10 of the WebGL 1.0 spec |
| 1814 | ERR( |
| 1815 | "This ANGLE implementation does not support separate front/back stencil " |
| 1816 | "writemasks, reference values, or stencil mask values."); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1817 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 1818 | return false; |
| 1819 | } |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1820 | } |
| 1821 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1822 | const gl::Framebuffer *fbo = state.getDrawFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1823 | if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1824 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1825 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1826 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1827 | } |
| 1828 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1829 | gl::Program *program = state.getProgram(); |
| 1830 | if (!program) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1831 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1832 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1833 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1834 | } |
| 1835 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1836 | if (!program->validateSamplers(NULL, context->getCaps())) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1837 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1838 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1839 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1840 | } |
| 1841 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1842 | // Uniform buffer validation |
| 1843 | for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 1844 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1845 | const gl::UniformBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1846 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1847 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 1848 | state.getIndexedUniformBuffer(blockBinding); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1849 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1850 | if (uniformBuffer.get() == nullptr) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1851 | { |
| 1852 | // undefined behaviour |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1853 | context->handleError( |
| 1854 | Error(GL_INVALID_OPERATION, |
| 1855 | "It is undefined behaviour to have a used but unbound uniform buffer.")); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1856 | return false; |
| 1857 | } |
| 1858 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1859 | size_t uniformBufferSize = uniformBuffer.getSize(); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1860 | if (uniformBufferSize == 0) |
| 1861 | { |
| 1862 | // Bind the whole buffer. |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 1863 | uniformBufferSize = static_cast<size_t>(uniformBuffer->getSize()); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 1866 | if (uniformBufferSize < uniformBlock.dataSize) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1867 | { |
| 1868 | // undefined behaviour |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1869 | context->handleError( |
| 1870 | Error(GL_INVALID_OPERATION, |
| 1871 | "It is undefined behaviour to use a uniform buffer that is too small.")); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1872 | return false; |
| 1873 | } |
| 1874 | } |
| 1875 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1876 | // No-op if zero count |
| 1877 | return (count > 0); |
| 1878 | } |
| 1879 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1880 | bool ValidateDrawArrays(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1881 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1882 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1883 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1884 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1885 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1886 | } |
| 1887 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1888 | const State &state = context->getState(); |
| 1889 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1890 | if (curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused() && |
| 1891 | curTransformFeedback->getPrimitiveMode() != mode) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1892 | { |
| 1893 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 1894 | // that does not match the current transform feedback object's draw mode (if transform feedback |
| 1895 | // is active), (3.0.2, section 2.14, pg 86) |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1896 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1897 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1898 | } |
| 1899 | |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 1900 | if (!ValidateDrawBase(context, mode, count, primcount)) |
| 1901 | { |
| 1902 | return false; |
| 1903 | } |
| 1904 | |
| 1905 | if (!ValidateDrawAttribs(context, primcount, count)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1906 | { |
| 1907 | return false; |
| 1908 | } |
| 1909 | |
| 1910 | return true; |
| 1911 | } |
| 1912 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1913 | bool ValidateDrawArraysInstanced(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1914 | { |
| 1915 | if (primcount < 0) |
| 1916 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1917 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1918 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1919 | } |
| 1920 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1921 | if (!ValidateDrawArrays(context, mode, first, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1922 | { |
| 1923 | return false; |
| 1924 | } |
| 1925 | |
| 1926 | // No-op if zero primitive count |
| 1927 | return (primcount > 0); |
| 1928 | } |
| 1929 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1930 | static bool ValidateDrawInstancedANGLE(Context *context) |
| 1931 | { |
| 1932 | // Verify there is at least one active attribute with a divisor of zero |
| 1933 | const gl::State& state = context->getState(); |
| 1934 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1935 | gl::Program *program = state.getProgram(); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1936 | |
| 1937 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 1938 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1939 | { |
| 1940 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 1941 | if (program->isAttribLocationActive(attributeIndex) && attrib.divisor == 0) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1942 | { |
| 1943 | return true; |
| 1944 | } |
| 1945 | } |
| 1946 | |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1947 | context->handleError(Error(GL_INVALID_OPERATION, |
| 1948 | "ANGLE_instanced_arrays requires that at least one active attribute" |
| 1949 | "has a divisor of zero.")); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1950 | return false; |
| 1951 | } |
| 1952 | |
| 1953 | bool ValidateDrawArraysInstancedANGLE(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
| 1954 | { |
| 1955 | if (!ValidateDrawInstancedANGLE(context)) |
| 1956 | { |
| 1957 | return false; |
| 1958 | } |
| 1959 | |
| 1960 | return ValidateDrawArraysInstanced(context, mode, first, count, primcount); |
| 1961 | } |
| 1962 | |
Jamie Madill | f25855c | 2015-11-03 11:06:18 -0500 | [diff] [blame] | 1963 | bool ValidateDrawElements(ValidationContext *context, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 1964 | GLenum mode, |
| 1965 | GLsizei count, |
| 1966 | GLenum type, |
| 1967 | const GLvoid *indices, |
| 1968 | GLsizei primcount, |
| 1969 | IndexRange *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1970 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1971 | switch (type) |
| 1972 | { |
| 1973 | case GL_UNSIGNED_BYTE: |
| 1974 | case GL_UNSIGNED_SHORT: |
| 1975 | break; |
| 1976 | case GL_UNSIGNED_INT: |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 1977 | if (context->getClientVersion() < 3 && !context->getExtensions().elementIndexUint) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1978 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1979 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1980 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1981 | } |
| 1982 | break; |
| 1983 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1984 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1985 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1986 | } |
| 1987 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1988 | const State &state = context->getState(); |
| 1989 | |
| 1990 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1991 | if (curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1992 | { |
| 1993 | // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced |
| 1994 | // while transform feedback is active, (3.0.2, section 2.14, pg 86) |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1995 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1996 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2000 | if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2001 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2002 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2003 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2004 | } |
| 2005 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 2006 | const gl::VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 2007 | gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 2008 | if (!indices && !elementArrayBuffer) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2009 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2010 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2011 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2012 | } |
| 2013 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 2014 | if (elementArrayBuffer) |
| 2015 | { |
| 2016 | const gl::Type &typeInfo = gl::GetTypeInfo(type); |
| 2017 | |
| 2018 | GLint64 offset = reinterpret_cast<GLint64>(indices); |
| 2019 | GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset; |
| 2020 | |
| 2021 | // check for integer overflows |
| 2022 | if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) || |
| 2023 | byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max())) |
| 2024 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2025 | context->handleError(Error(GL_OUT_OF_MEMORY)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2026 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | // Check for reading past the end of the bound buffer object |
| 2030 | if (byteCount > elementArrayBuffer->getSize()) |
| 2031 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2032 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2033 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 2034 | } |
| 2035 | } |
| 2036 | else if (!indices) |
| 2037 | { |
| 2038 | // Catch this programming error here |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2039 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2040 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 2041 | } |
| 2042 | |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2043 | if (!ValidateDrawBase(context, mode, count, primcount)) |
| 2044 | { |
| 2045 | return false; |
| 2046 | } |
| 2047 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 2048 | // Use max index to validate if our vertex buffers are large enough for the pull. |
| 2049 | // TODO: offer fast path, with disabled index validation. |
| 2050 | // TODO: also disable index checking on back-ends that are robust to out-of-range accesses. |
| 2051 | if (elementArrayBuffer) |
| 2052 | { |
Jacek Caban | a5521de | 2014-10-01 17:23:46 +0200 | [diff] [blame] | 2053 | uintptr_t offset = reinterpret_cast<uintptr_t>(indices); |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 2054 | Error error = |
| 2055 | elementArrayBuffer->getIndexRange(type, static_cast<size_t>(offset), count, |
| 2056 | state.isPrimitiveRestartEnabled(), indexRangeOut); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 2057 | if (error.isError()) |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 2058 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2059 | context->handleError(error); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 2060 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | else |
| 2064 | { |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 2065 | *indexRangeOut = ComputeIndexRange(type, indices, count, state.isPrimitiveRestartEnabled()); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 2066 | } |
| 2067 | |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 2068 | // If we use an index greater than our maximum supported index range, return an error. |
| 2069 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 2070 | // return an error if possible here. |
| 2071 | if (static_cast<GLuint64>(indexRangeOut->end) >= context->getCaps().maxElementIndex) |
| 2072 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2073 | context->handleError(Error(GL_INVALID_OPERATION, g_ExceedsMaxElementErrorMessage)); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 2074 | return false; |
| 2075 | } |
| 2076 | |
Jamie Madill | bc4c4bc | 2016-03-23 21:04:43 -0400 | [diff] [blame] | 2077 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRangeOut->vertexCount()))) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2078 | { |
| 2079 | return false; |
| 2080 | } |
| 2081 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 2082 | // No op if there are no real indices in the index data (all are primitive restart). |
| 2083 | return (indexRangeOut->vertexIndexCount > 0); |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2084 | } |
| 2085 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2086 | bool ValidateDrawElementsInstanced(Context *context, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 2087 | GLenum mode, |
| 2088 | GLsizei count, |
| 2089 | GLenum type, |
| 2090 | const GLvoid *indices, |
| 2091 | GLsizei primcount, |
| 2092 | IndexRange *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2093 | { |
| 2094 | if (primcount < 0) |
| 2095 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2096 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2097 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2098 | } |
| 2099 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 2100 | if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2101 | { |
| 2102 | return false; |
| 2103 | } |
| 2104 | |
| 2105 | // No-op zero primitive count |
| 2106 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2107 | } |
| 2108 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 2109 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
| 2110 | GLenum mode, |
| 2111 | GLsizei count, |
| 2112 | GLenum type, |
| 2113 | const GLvoid *indices, |
| 2114 | GLsizei primcount, |
| 2115 | IndexRange *indexRangeOut) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2116 | { |
| 2117 | if (!ValidateDrawInstancedANGLE(context)) |
| 2118 | { |
| 2119 | return false; |
| 2120 | } |
| 2121 | |
| 2122 | return ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, indexRangeOut); |
| 2123 | } |
| 2124 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2125 | bool ValidateFramebufferTextureBase(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2126 | GLuint texture, GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 2127 | { |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2128 | if (!ValidFramebufferTarget(target)) |
| 2129 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2130 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2131 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 2135 | { |
| 2136 | return false; |
| 2137 | } |
| 2138 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2139 | if (texture != 0) |
| 2140 | { |
| 2141 | gl::Texture *tex = context->getTexture(texture); |
| 2142 | |
| 2143 | if (tex == NULL) |
| 2144 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2145 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2146 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | if (level < 0) |
| 2150 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2151 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2152 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2156 | const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 2157 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2158 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 2159 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2160 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2161 | context->handleError( |
| 2162 | Error(GL_INVALID_OPERATION, "Cannot change default FBO's attachments")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2163 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | return true; |
| 2167 | } |
| 2168 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2169 | bool ValidateFramebufferTexture2D(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2170 | GLenum textarget, GLuint texture, GLint level) |
| 2171 | { |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 2172 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap extension |
| 2173 | if (context->getClientVersion() < 3 && !context->getExtensions().fboRenderMipmap && level != 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2174 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2175 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2176 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 2180 | { |
| 2181 | return false; |
| 2182 | } |
| 2183 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2184 | if (texture != 0) |
| 2185 | { |
| 2186 | gl::Texture *tex = context->getTexture(texture); |
| 2187 | ASSERT(tex); |
| 2188 | |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 2189 | const gl::Caps &caps = context->getCaps(); |
| 2190 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2191 | switch (textarget) |
| 2192 | { |
| 2193 | case GL_TEXTURE_2D: |
| 2194 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 2195 | if (level > gl::log2(caps.max2DTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2196 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2197 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2198 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2199 | } |
| 2200 | if (tex->getTarget() != GL_TEXTURE_2D) |
| 2201 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2202 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2203 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2204 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2205 | } |
| 2206 | break; |
| 2207 | |
| 2208 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 2209 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 2210 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 2211 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 2212 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 2213 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 2214 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 2215 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2216 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2217 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2218 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2219 | } |
| 2220 | if (tex->getTarget() != GL_TEXTURE_CUBE_MAP) |
| 2221 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2222 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2223 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2224 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2225 | } |
| 2226 | break; |
| 2227 | |
| 2228 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2229 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2230 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2231 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2232 | |
| 2233 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(textarget, level)); |
| 2234 | if (internalFormatInfo.compressed) |
| 2235 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2236 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2237 | return false; |
| 2238 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2239 | } |
| 2240 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 2241 | return true; |
| 2242 | } |
| 2243 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2244 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2245 | { |
| 2246 | if (program == 0) |
| 2247 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2248 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2249 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2250 | } |
| 2251 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 2252 | gl::Program *programObject = GetValidProgram(context, program); |
| 2253 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 2254 | { |
| 2255 | return false; |
| 2256 | } |
| 2257 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2258 | if (!programObject || !programObject->isLinked()) |
| 2259 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2260 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2261 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2262 | } |
| 2263 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2264 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 2265 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2266 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2267 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 2268 | } |
| 2269 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2270 | return true; |
| 2271 | } |
| 2272 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2273 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat* params) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 2274 | { |
| 2275 | return ValidateGetUniformBase(context, program, location); |
| 2276 | } |
| 2277 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2278 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2279 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 2280 | return ValidateGetUniformBase(context, program, location); |
| 2281 | } |
| 2282 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2283 | static bool ValidateSizedGetUniform(Context *context, GLuint program, GLint location, GLsizei bufSize) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 2284 | { |
| 2285 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2286 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 2287 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2288 | } |
| 2289 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 2290 | gl::Program *programObject = context->getProgram(program); |
| 2291 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2292 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 2293 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2294 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
| 2295 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 2296 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2297 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2298 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2299 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | return true; |
| 2303 | } |
| 2304 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2305 | bool ValidateGetnUniformfvEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2306 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 2307 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2308 | } |
| 2309 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2310 | bool ValidateGetnUniformivEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2311 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 2312 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2313 | } |
| 2314 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2315 | bool ValidateDiscardFramebufferBase(Context *context, GLenum target, GLsizei numAttachments, |
| 2316 | const GLenum *attachments, bool defaultFramebuffer) |
| 2317 | { |
| 2318 | if (numAttachments < 0) |
| 2319 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2320 | context->handleError(Error(GL_INVALID_VALUE, "numAttachments must not be less than zero")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2321 | return false; |
| 2322 | } |
| 2323 | |
| 2324 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 2325 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 2326 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2327 | { |
| 2328 | if (defaultFramebuffer) |
| 2329 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2330 | context->handleError(Error( |
| 2331 | GL_INVALID_ENUM, "Invalid attachment when the default framebuffer is bound")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2332 | return false; |
| 2333 | } |
| 2334 | |
| 2335 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 2336 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2337 | context->handleError(Error(GL_INVALID_OPERATION, |
| 2338 | "Requested color attachment is greater than the maximum " |
| 2339 | "supported color attachments")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2340 | return false; |
| 2341 | } |
| 2342 | } |
| 2343 | else |
| 2344 | { |
| 2345 | switch (attachments[i]) |
| 2346 | { |
| 2347 | case GL_DEPTH_ATTACHMENT: |
| 2348 | case GL_STENCIL_ATTACHMENT: |
| 2349 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 2350 | if (defaultFramebuffer) |
| 2351 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2352 | context->handleError( |
| 2353 | Error(GL_INVALID_ENUM, |
| 2354 | "Invalid attachment when the default framebuffer is bound")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2355 | return false; |
| 2356 | } |
| 2357 | break; |
| 2358 | case GL_COLOR: |
| 2359 | case GL_DEPTH: |
| 2360 | case GL_STENCIL: |
| 2361 | if (!defaultFramebuffer) |
| 2362 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2363 | context->handleError( |
| 2364 | Error(GL_INVALID_ENUM, |
| 2365 | "Invalid attachment when the default framebuffer is not bound")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2366 | return false; |
| 2367 | } |
| 2368 | break; |
| 2369 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2370 | context->handleError(Error(GL_INVALID_ENUM, "Invalid attachment")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 2371 | return false; |
| 2372 | } |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | return true; |
| 2377 | } |
| 2378 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 2379 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 2380 | { |
| 2381 | // Note that debug marker calls must not set error state |
| 2382 | |
| 2383 | if (length < 0) |
| 2384 | { |
| 2385 | return false; |
| 2386 | } |
| 2387 | |
| 2388 | if (marker == nullptr) |
| 2389 | { |
| 2390 | return false; |
| 2391 | } |
| 2392 | |
| 2393 | return true; |
| 2394 | } |
| 2395 | |
| 2396 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 2397 | { |
| 2398 | // Note that debug marker calls must not set error state |
| 2399 | |
| 2400 | if (length < 0) |
| 2401 | { |
| 2402 | return false; |
| 2403 | } |
| 2404 | |
| 2405 | if (length > 0 && marker == nullptr) |
| 2406 | { |
| 2407 | return false; |
| 2408 | } |
| 2409 | |
| 2410 | return true; |
| 2411 | } |
| 2412 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 2413 | bool ValidateEGLImageTargetTexture2DOES(Context *context, |
| 2414 | egl::Display *display, |
| 2415 | GLenum target, |
| 2416 | egl::Image *image) |
| 2417 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2418 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 2419 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2420 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2421 | return false; |
| 2422 | } |
| 2423 | |
| 2424 | switch (target) |
| 2425 | { |
| 2426 | case GL_TEXTURE_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 2427 | if (!context->getExtensions().eglImage) |
| 2428 | { |
| 2429 | context->handleError(Error( |
| 2430 | GL_INVALID_ENUM, "GL_TEXTURE_2D texture target requires GL_OES_EGL_image.")); |
| 2431 | } |
| 2432 | break; |
| 2433 | |
| 2434 | case GL_TEXTURE_EXTERNAL_OES: |
| 2435 | if (!context->getExtensions().eglImageExternal) |
| 2436 | { |
| 2437 | context->handleError(Error( |
| 2438 | GL_INVALID_ENUM, |
| 2439 | "GL_TEXTURE_EXTERNAL_OES texture target requires GL_OES_EGL_image_external.")); |
| 2440 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2441 | break; |
| 2442 | |
| 2443 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2444 | context->handleError(Error(GL_INVALID_ENUM, "invalid texture target.")); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2445 | return false; |
| 2446 | } |
| 2447 | |
| 2448 | if (!display->isValidImage(image)) |
| 2449 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2450 | context->handleError(Error(GL_INVALID_VALUE, "EGL image is not valid.")); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2451 | return false; |
| 2452 | } |
| 2453 | |
| 2454 | if (image->getSamples() > 0) |
| 2455 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2456 | context->handleError(Error(GL_INVALID_OPERATION, |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2457 | "cannot create a 2D texture from a multisampled EGL image.")); |
| 2458 | return false; |
| 2459 | } |
| 2460 | |
| 2461 | const TextureCaps &textureCaps = context->getTextureCaps().get(image->getInternalFormat()); |
| 2462 | if (!textureCaps.texturable) |
| 2463 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2464 | context->handleError(Error(GL_INVALID_OPERATION, |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2465 | "EGL image internal format is not supported as a texture.")); |
| 2466 | return false; |
| 2467 | } |
| 2468 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 2469 | return true; |
| 2470 | } |
| 2471 | |
| 2472 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
| 2473 | egl::Display *display, |
| 2474 | GLenum target, |
| 2475 | egl::Image *image) |
| 2476 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2477 | if (!context->getExtensions().eglImage) |
| 2478 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2479 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2480 | return false; |
| 2481 | } |
| 2482 | |
| 2483 | switch (target) |
| 2484 | { |
| 2485 | case GL_RENDERBUFFER: |
| 2486 | break; |
| 2487 | |
| 2488 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2489 | context->handleError(Error(GL_INVALID_ENUM, "invalid renderbuffer target.")); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2490 | return false; |
| 2491 | } |
| 2492 | |
| 2493 | if (!display->isValidImage(image)) |
| 2494 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2495 | context->handleError(Error(GL_INVALID_VALUE, "EGL image is not valid.")); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2496 | return false; |
| 2497 | } |
| 2498 | |
| 2499 | const TextureCaps &textureCaps = context->getTextureCaps().get(image->getInternalFormat()); |
| 2500 | if (!textureCaps.renderable) |
| 2501 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2502 | context->handleError(Error( |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2503 | GL_INVALID_OPERATION, "EGL image internal format is not supported as a renderbuffer.")); |
| 2504 | return false; |
| 2505 | } |
| 2506 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 2507 | return true; |
| 2508 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2509 | |
| 2510 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 2511 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2512 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2513 | { |
| 2514 | // The default VAO should always exist |
| 2515 | ASSERT(array != 0); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2516 | context->handleError(Error(GL_INVALID_OPERATION)); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 2517 | return false; |
| 2518 | } |
| 2519 | |
| 2520 | return true; |
| 2521 | } |
| 2522 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2523 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 2524 | { |
| 2525 | if (context->hasActiveTransformFeedback(program)) |
| 2526 | { |
| 2527 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2528 | context->handleError(Error(GL_INVALID_OPERATION, |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2529 | "Cannot link program while program is associated with an active " |
| 2530 | "transform feedback object.")); |
| 2531 | return false; |
| 2532 | } |
| 2533 | return true; |
| 2534 | } |
| 2535 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2536 | bool ValidateProgramBinaryBase(Context *context, |
| 2537 | GLuint program, |
| 2538 | GLenum binaryFormat, |
| 2539 | const void *binary, |
| 2540 | GLint length) |
| 2541 | { |
| 2542 | Program *programObject = GetValidProgram(context, program); |
| 2543 | if (programObject == nullptr) |
| 2544 | { |
| 2545 | return false; |
| 2546 | } |
| 2547 | |
| 2548 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 2549 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 2550 | programBinaryFormats.end()) |
| 2551 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2552 | context->handleError(Error(GL_INVALID_ENUM, "Program binary format is not valid.")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2553 | return false; |
| 2554 | } |
| 2555 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2556 | if (context->hasActiveTransformFeedback(program)) |
| 2557 | { |
| 2558 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2559 | context->handleError(Error(GL_INVALID_OPERATION, |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2560 | "Cannot change program binary while program is associated with " |
| 2561 | "an active transform feedback object.")); |
| 2562 | return false; |
| 2563 | } |
| 2564 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2565 | return true; |
| 2566 | } |
| 2567 | |
| 2568 | bool ValidateGetProgramBinaryBase(Context *context, |
| 2569 | GLuint program, |
| 2570 | GLsizei bufSize, |
| 2571 | GLsizei *length, |
| 2572 | GLenum *binaryFormat, |
| 2573 | void *binary) |
| 2574 | { |
| 2575 | Program *programObject = GetValidProgram(context, program); |
| 2576 | if (programObject == nullptr) |
| 2577 | { |
| 2578 | return false; |
| 2579 | } |
| 2580 | |
| 2581 | if (!programObject->isLinked()) |
| 2582 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2583 | context->handleError(Error(GL_INVALID_OPERATION, "Program is not linked.")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 2584 | return false; |
| 2585 | } |
| 2586 | |
| 2587 | return true; |
| 2588 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2589 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2590 | bool ValidateUseProgram(Context *context, GLuint program) |
| 2591 | { |
| 2592 | if (program != 0) |
| 2593 | { |
| 2594 | Program *programObject = context->getProgram(program); |
| 2595 | if (!programObject) |
| 2596 | { |
| 2597 | // ES 3.1.0 section 7.3 page 72 |
| 2598 | if (context->getShader(program)) |
| 2599 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2600 | context->handleError( |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2601 | Error(GL_INVALID_OPERATION, |
| 2602 | "Attempted to use a single shader instead of a shader program.")); |
| 2603 | return false; |
| 2604 | } |
| 2605 | else |
| 2606 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2607 | context->handleError(Error(GL_INVALID_VALUE, "Program invalid.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2608 | return false; |
| 2609 | } |
| 2610 | } |
| 2611 | if (!programObject->isLinked()) |
| 2612 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2613 | context->handleError(Error(GL_INVALID_OPERATION, "Program not linked.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2614 | return false; |
| 2615 | } |
| 2616 | } |
| 2617 | if (context->getState().isTransformFeedbackActiveUnpaused()) |
| 2618 | { |
| 2619 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2620 | context->handleError( |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2621 | Error(GL_INVALID_OPERATION, |
| 2622 | "Cannot change active program while transform feedback is unpaused.")); |
| 2623 | return false; |
| 2624 | } |
| 2625 | |
| 2626 | return true; |
| 2627 | } |
| 2628 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2629 | bool ValidateCopyTexImage2D(ValidationContext *context, |
| 2630 | GLenum target, |
| 2631 | GLint level, |
| 2632 | GLenum internalformat, |
| 2633 | GLint x, |
| 2634 | GLint y, |
| 2635 | GLsizei width, |
| 2636 | GLsizei height, |
| 2637 | GLint border) |
| 2638 | { |
| 2639 | if (context->getClientVersion() < 3) |
| 2640 | { |
| 2641 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 2642 | 0, x, y, width, height, border); |
| 2643 | } |
| 2644 | |
| 2645 | ASSERT(context->getClientVersion() == 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 2646 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 2647 | 0, x, y, width, height, border); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2648 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2649 | |
| 2650 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 2651 | GLenum target, |
| 2652 | GLenum attachment, |
| 2653 | GLenum renderbuffertarget, |
| 2654 | GLuint renderbuffer) |
| 2655 | { |
| 2656 | if (!ValidFramebufferTarget(target) || |
| 2657 | (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)) |
| 2658 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2659 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2660 | return false; |
| 2661 | } |
| 2662 | |
| 2663 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 2664 | renderbuffertarget, renderbuffer); |
| 2665 | } |
| 2666 | |
| 2667 | bool ValidateDrawBuffersBase(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 2668 | { |
| 2669 | // INVALID_VALUE is generated if n is negative or greater than value of MAX_DRAW_BUFFERS |
| 2670 | if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 2671 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2672 | context->handleError( |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2673 | Error(GL_INVALID_VALUE, "n must be non-negative and no greater than MAX_DRAW_BUFFERS")); |
| 2674 | return false; |
| 2675 | } |
| 2676 | |
| 2677 | ASSERT(context->getState().getDrawFramebuffer()); |
| 2678 | GLuint frameBufferId = context->getState().getDrawFramebuffer()->id(); |
| 2679 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 2680 | |
| 2681 | // This should come first before the check for the default frame buffer |
| 2682 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 2683 | // rather than INVALID_OPERATION |
| 2684 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 2685 | { |
| 2686 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 2687 | |
| 2688 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 2689 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 2690 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2691 | { |
| 2692 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 2693 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 2694 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 2695 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 2696 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2697 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer value")); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 2698 | return false; |
| 2699 | } |
| 2700 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 2701 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2702 | context->handleError( |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 2703 | Error(GL_INVALID_OPERATION, "Buffer value is greater than MAX_DRAW_BUFFERS")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2704 | return false; |
| 2705 | } |
| 2706 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 2707 | frameBufferId != 0) |
| 2708 | { |
| 2709 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 2710 | // is not COLOR_ATTACHMENTi or NONE |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2711 | context->handleError( |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2712 | Error(GL_INVALID_OPERATION, "Ith value does not match COLOR_ATTACHMENTi or NONE")); |
| 2713 | return false; |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 2718 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 2719 | if (frameBufferId == 0) |
| 2720 | { |
| 2721 | if (n != 1) |
| 2722 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2723 | context->handleError(Error(GL_INVALID_OPERATION, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2724 | "n must be 1 when GL is bound to the default framebuffer")); |
| 2725 | return false; |
| 2726 | } |
| 2727 | |
| 2728 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 2729 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2730 | context->handleError(Error( |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2731 | GL_INVALID_OPERATION, |
| 2732 | "Only NONE or BACK are valid values when drawing to the default framebuffer")); |
| 2733 | return false; |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | return true; |
| 2738 | } |
| 2739 | |
| 2740 | bool ValidateCopyTexSubImage2D(Context *context, |
| 2741 | GLenum target, |
| 2742 | GLint level, |
| 2743 | GLint xoffset, |
| 2744 | GLint yoffset, |
| 2745 | GLint x, |
| 2746 | GLint y, |
| 2747 | GLsizei width, |
| 2748 | GLsizei height) |
| 2749 | { |
| 2750 | if (context->getClientVersion() < 3) |
| 2751 | { |
| 2752 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 2753 | yoffset, x, y, width, height, 0); |
| 2754 | } |
| 2755 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 2756 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 2757 | yoffset, 0, x, y, width, height, 0); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2758 | } |
| 2759 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2760 | bool ValidateGetBufferPointervBase(Context *context, GLenum target, GLenum pname, void **params) |
| 2761 | { |
| 2762 | if (!ValidBufferTarget(context, target)) |
| 2763 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2764 | context->handleError(Error(GL_INVALID_ENUM, "Buffer target not valid: 0x%X", target)); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2765 | return false; |
| 2766 | } |
| 2767 | |
| 2768 | if (pname != GL_BUFFER_MAP_POINTER) |
| 2769 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2770 | context->handleError(Error(GL_INVALID_ENUM, "pname not valid: 0x%X", pname)); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2771 | return false; |
| 2772 | } |
| 2773 | |
| 2774 | Buffer *buffer = context->getState().getTargetBuffer(target); |
| 2775 | |
| 2776 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 2777 | // target bound to zero generate an INVALID_OPERATION error." |
| 2778 | // GLES 3.1 section 6.6 explicitly specifies this error. |
| 2779 | if (!buffer) |
| 2780 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2781 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2782 | Error(GL_INVALID_OPERATION, "Can not get pointer for reserved buffer name zero.")); |
| 2783 | return false; |
| 2784 | } |
| 2785 | |
| 2786 | return true; |
| 2787 | } |
| 2788 | |
| 2789 | bool ValidateUnmapBufferBase(Context *context, GLenum target) |
| 2790 | { |
| 2791 | if (!ValidBufferTarget(context, target)) |
| 2792 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2793 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2794 | return false; |
| 2795 | } |
| 2796 | |
| 2797 | Buffer *buffer = context->getState().getTargetBuffer(target); |
| 2798 | |
| 2799 | if (buffer == nullptr || !buffer->isMapped()) |
| 2800 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2801 | context->handleError(Error(GL_INVALID_OPERATION, "Buffer not mapped.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2802 | return false; |
| 2803 | } |
| 2804 | |
| 2805 | return true; |
| 2806 | } |
| 2807 | |
| 2808 | bool ValidateMapBufferRangeBase(Context *context, |
| 2809 | GLenum target, |
| 2810 | GLintptr offset, |
| 2811 | GLsizeiptr length, |
| 2812 | GLbitfield access) |
| 2813 | { |
| 2814 | if (!ValidBufferTarget(context, target)) |
| 2815 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2816 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2817 | return false; |
| 2818 | } |
| 2819 | |
| 2820 | if (offset < 0 || length < 0) |
| 2821 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2822 | context->handleError(Error(GL_INVALID_VALUE, "Invalid offset or length.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2823 | return false; |
| 2824 | } |
| 2825 | |
| 2826 | Buffer *buffer = context->getState().getTargetBuffer(target); |
| 2827 | |
| 2828 | if (!buffer) |
| 2829 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2830 | context->handleError(Error(GL_INVALID_OPERATION, "Attempted to map buffer object zero.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2831 | return false; |
| 2832 | } |
| 2833 | |
| 2834 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2835 | CheckedNumeric<size_t> checkedOffset(offset); |
| 2836 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2837 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2838 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2839 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2840 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2841 | Error(GL_INVALID_VALUE, "Mapped range does not fit into buffer dimensions.")); |
| 2842 | return false; |
| 2843 | } |
| 2844 | |
| 2845 | // Check for invalid bits in the mask |
| 2846 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 2847 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 2848 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 2849 | |
| 2850 | if (access & ~(allAccessBits)) |
| 2851 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2852 | context->handleError(Error(GL_INVALID_VALUE, "Invalid access bits: 0x%X.", access)); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2853 | return false; |
| 2854 | } |
| 2855 | |
| 2856 | if (length == 0) |
| 2857 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2858 | context->handleError(Error(GL_INVALID_OPERATION, "Buffer mapping length is zero.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2859 | return false; |
| 2860 | } |
| 2861 | |
| 2862 | if (buffer->isMapped()) |
| 2863 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2864 | context->handleError(Error(GL_INVALID_OPERATION, "Buffer is already mapped.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2865 | return false; |
| 2866 | } |
| 2867 | |
| 2868 | // Check for invalid bit combinations |
| 2869 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 2870 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2871 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2872 | Error(GL_INVALID_OPERATION, "Need to map buffer for either reading or writing.")); |
| 2873 | return false; |
| 2874 | } |
| 2875 | |
| 2876 | GLbitfield writeOnlyBits = |
| 2877 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 2878 | |
| 2879 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 2880 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2881 | context->handleError(Error(GL_INVALID_OPERATION, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2882 | "Invalid access bits when mapping buffer for reading: 0x%X.", |
| 2883 | access)); |
| 2884 | return false; |
| 2885 | } |
| 2886 | |
| 2887 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 2888 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2889 | context->handleError(Error( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2890 | GL_INVALID_OPERATION, |
| 2891 | "The explicit flushing bit may only be set if the buffer is mapped for writing.")); |
| 2892 | return false; |
| 2893 | } |
| 2894 | return true; |
| 2895 | } |
| 2896 | |
| 2897 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
| 2898 | GLenum target, |
| 2899 | GLintptr offset, |
| 2900 | GLsizeiptr length) |
| 2901 | { |
| 2902 | if (offset < 0 || length < 0) |
| 2903 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2904 | context->handleError(Error(GL_INVALID_VALUE, "Invalid offset/length parameters.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2905 | return false; |
| 2906 | } |
| 2907 | |
| 2908 | if (!ValidBufferTarget(context, target)) |
| 2909 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2910 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2911 | return false; |
| 2912 | } |
| 2913 | |
| 2914 | Buffer *buffer = context->getState().getTargetBuffer(target); |
| 2915 | |
| 2916 | if (buffer == nullptr) |
| 2917 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2918 | context->handleError(Error(GL_INVALID_OPERATION, "Attempted to flush buffer object zero.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2919 | return false; |
| 2920 | } |
| 2921 | |
| 2922 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 2923 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2924 | context->handleError(Error( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2925 | GL_INVALID_OPERATION, "Attempted to flush a buffer not mapped for explicit flushing.")); |
| 2926 | return false; |
| 2927 | } |
| 2928 | |
| 2929 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2930 | CheckedNumeric<size_t> checkedOffset(offset); |
| 2931 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2932 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2933 | if (!checkedSize.IsValid() || |
| 2934 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2935 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2936 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2937 | Error(GL_INVALID_VALUE, "Flushed range does not fit into buffer mapping dimensions.")); |
| 2938 | return false; |
| 2939 | } |
| 2940 | |
| 2941 | return true; |
| 2942 | } |
| 2943 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 2944 | bool ValidateGenerateMipmap(Context *context, GLenum target) |
| 2945 | { |
| 2946 | if (!ValidTextureTarget(context, target)) |
| 2947 | { |
| 2948 | context->handleError(Error(GL_INVALID_ENUM)); |
| 2949 | return false; |
| 2950 | } |
| 2951 | |
| 2952 | Texture *texture = context->getTargetTexture(target); |
| 2953 | |
| 2954 | if (texture == nullptr) |
| 2955 | { |
| 2956 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 2957 | return false; |
| 2958 | } |
| 2959 | |
| 2960 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 2961 | |
| 2962 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 2963 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 2964 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 2965 | { |
| 2966 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 2967 | return false; |
| 2968 | } |
| 2969 | |
| 2970 | GLenum baseTarget = (target == GL_TEXTURE_CUBE_MAP) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : target; |
| 2971 | GLenum internalFormat = texture->getInternalFormat(baseTarget, effectiveBaseLevel); |
| 2972 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 2973 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat); |
| 2974 | |
| 2975 | // GenerateMipmap should not generate an INVALID_OPERATION for textures created with |
| 2976 | // unsized formats or that are color renderable and filterable. Since we do not track if |
| 2977 | // the texture was created with sized or unsized format (only sized formats are stored), |
| 2978 | // it is not possible to make sure the the LUMA formats can generate mipmaps (they should |
| 2979 | // be able to) because they aren't color renderable. Simply do a special case for LUMA |
| 2980 | // textures since they're the only texture format that can be created with unsized formats |
| 2981 | // that is not color renderable. New unsized formats are unlikely to be added, since ES2 |
| 2982 | // was the last version to use add them. |
| 2983 | bool isLUMA = internalFormat == GL_LUMINANCE8_EXT || |
| 2984 | internalFormat == GL_LUMINANCE8_ALPHA8_EXT || internalFormat == GL_ALPHA8_EXT; |
| 2985 | |
| 2986 | if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable || |
| 2987 | (!formatCaps.renderable && !isLUMA) || formatInfo.compressed) |
| 2988 | { |
| 2989 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 2990 | return false; |
| 2991 | } |
| 2992 | |
| 2993 | // GL_EXT_sRGB does not support mipmap generation on sRGB textures |
| 2994 | if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB) |
| 2995 | { |
| 2996 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 2997 | return false; |
| 2998 | } |
| 2999 | |
| 3000 | // Non-power of 2 ES2 check |
| 3001 | if (!context->getExtensions().textureNPOT && |
| 3002 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 3003 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 3004 | { |
| 3005 | ASSERT(context->getClientVersion() <= 2 && |
| 3006 | (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP)); |
| 3007 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 3008 | return false; |
| 3009 | } |
| 3010 | |
| 3011 | // Cube completeness check |
| 3012 | if (target == GL_TEXTURE_CUBE_MAP && !texture->getTextureState().isCubeComplete()) |
| 3013 | { |
| 3014 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 3015 | return false; |
| 3016 | } |
| 3017 | |
| 3018 | return true; |
| 3019 | } |
| 3020 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3021 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 3022 | { |
| 3023 | return ValidateGenOrDelete(context, n); |
| 3024 | } |
| 3025 | |
| 3026 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 3027 | { |
| 3028 | return ValidateGenOrDelete(context, n); |
| 3029 | } |
| 3030 | |
| 3031 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 3032 | { |
| 3033 | return ValidateGenOrDelete(context, n); |
| 3034 | } |
| 3035 | |
| 3036 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 3037 | { |
| 3038 | return ValidateGenOrDelete(context, n); |
| 3039 | } |
| 3040 | |
| 3041 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 3042 | { |
| 3043 | return ValidateGenOrDelete(context, n); |
| 3044 | } |
| 3045 | |
| 3046 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 3047 | { |
| 3048 | return ValidateGenOrDelete(context, n); |
| 3049 | } |
| 3050 | |
| 3051 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 3052 | { |
| 3053 | return ValidateGenOrDelete(context, n); |
| 3054 | } |
| 3055 | |
| 3056 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 3057 | { |
| 3058 | return ValidateGenOrDelete(context, n); |
| 3059 | } |
| 3060 | |
| 3061 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 3062 | { |
| 3063 | if (n < 0) |
| 3064 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3065 | context->handleError(Error(GL_INVALID_VALUE, "n < 0")); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3066 | return false; |
| 3067 | } |
| 3068 | return true; |
| 3069 | } |
| 3070 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3071 | } // namespace gl |