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