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