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