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