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