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