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