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 | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1148 | static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType, |
| 1149 | GLint location, GLsizei count, LinkedUniform **uniformOut) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1150 | { |
| 1151 | if (count < 0) |
| 1152 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1153 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1154 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1155 | } |
| 1156 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1157 | gl::Program *program = context->getState().getProgram(); |
| 1158 | if (!program) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1159 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1160 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1161 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | if (location == -1) |
| 1165 | { |
| 1166 | // Silently ignore the uniform command |
| 1167 | return false; |
| 1168 | } |
| 1169 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1170 | if (!program->isValidUniformLocation(location)) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1171 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1172 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1173 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1174 | } |
| 1175 | |
Jamie Madill | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1176 | LinkedUniform *uniform = program->getUniformByLocation(location); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1177 | |
| 1178 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
Jamie Madill | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1179 | if (!uniform->isArray() && count > 1) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1180 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1181 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1182 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
Jamie Madill | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1185 | *uniformOut = uniform; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1186 | return true; |
| 1187 | } |
| 1188 | |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1189 | bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count) |
| 1190 | { |
| 1191 | // Check for ES3 uniform entry points |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1192 | if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1193 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1194 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1195 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
Jamie Madill | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1198 | LinkedUniform *uniform = NULL; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1199 | if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform)) |
| 1200 | { |
| 1201 | return false; |
| 1202 | } |
| 1203 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1204 | GLenum targetBoolType = VariableBoolVectorType(uniformType); |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 1205 | bool samplerUniformCheck = (IsSamplerType(uniform->type) && uniformType == GL_INT); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1206 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 1207 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1208 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1209 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count, |
| 1216 | GLboolean transpose) |
| 1217 | { |
| 1218 | // Check for ES3 uniform entry points |
| 1219 | int rows = VariableRowCount(matrixType); |
| 1220 | int cols = VariableColumnCount(matrixType); |
| 1221 | if (rows != cols && context->getClientVersion() < 3) |
| 1222 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1223 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1224 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | if (transpose != GL_FALSE && context->getClientVersion() < 3) |
| 1228 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1229 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1230 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
Jamie Madill | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1233 | LinkedUniform *uniform = NULL; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1234 | if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform)) |
| 1235 | { |
| 1236 | return false; |
| 1237 | } |
| 1238 | |
| 1239 | if (uniform->type != matrixType) |
| 1240 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1241 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1242 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1246 | } |
| 1247 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1248 | bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
| 1249 | { |
| 1250 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 1251 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1252 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1253 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 1256 | const Caps &caps = context->getCaps(); |
| 1257 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1258 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 1259 | { |
| 1260 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 1261 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 1262 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1263 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1264 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1265 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | switch (pname) |
| 1270 | { |
| 1271 | case GL_TEXTURE_BINDING_2D: |
| 1272 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1273 | case GL_TEXTURE_BINDING_3D: |
| 1274 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 1275 | if (context->getState().getActiveSampler() >= caps.maxCombinedTextureImageUnits) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1276 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1277 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1278 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1279 | } |
| 1280 | break; |
| 1281 | |
| 1282 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1283 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1284 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1285 | Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1286 | ASSERT(framebuffer); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1287 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1288 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1289 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1290 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1293 | const FramebufferAttachment *attachment = framebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 1294 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1295 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1296 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1297 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | break; |
| 1301 | |
| 1302 | default: |
| 1303 | break; |
| 1304 | } |
| 1305 | |
| 1306 | // pname is valid, but there are no parameters to return |
| 1307 | if (numParams == 0) |
| 1308 | { |
| 1309 | return false; |
| 1310 | } |
| 1311 | |
| 1312 | return true; |
| 1313 | } |
| 1314 | |
Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame] | 1315 | 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] | 1316 | GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, |
| 1317 | GLint border, GLenum *textureFormatOut) |
| 1318 | { |
| 1319 | |
| 1320 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1321 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1322 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1323 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0) |
| 1327 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1328 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1329 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1333 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1334 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1335 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | if (border != 0) |
| 1339 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1340 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1341 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | if (!ValidMipLevel(context, target, level)) |
| 1345 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1346 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1347 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1348 | } |
| 1349 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1350 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1351 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1352 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1353 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1354 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1357 | if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1358 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1359 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1360 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1361 | } |
| 1362 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1363 | const gl::Caps &caps = context->getCaps(); |
| 1364 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1365 | GLuint maxDimension = 0; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1366 | switch (target) |
| 1367 | { |
| 1368 | case GL_TEXTURE_2D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1369 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1370 | break; |
| 1371 | |
| 1372 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1373 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1374 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1375 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1376 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1377 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1378 | maxDimension = caps.maxCubeMapTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1379 | break; |
| 1380 | |
| 1381 | case GL_TEXTURE_2D_ARRAY: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1382 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1383 | break; |
| 1384 | |
| 1385 | case GL_TEXTURE_3D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1386 | maxDimension = caps.max3DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1387 | break; |
| 1388 | |
| 1389 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1390 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1391 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1394 | gl::Texture *texture = context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1395 | if (!texture) |
| 1396 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1397 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1398 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | if (texture->isImmutable() && !isSubImage) |
| 1402 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1403 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1404 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1405 | } |
| 1406 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1407 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1408 | |
| 1409 | if (formatInfo.depthBits > 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1410 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1411 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1412 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1415 | if (formatInfo.compressed && !ValidCompressedImageSize(context, internalformat, width, height)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1416 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1417 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1418 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | if (isSubImage) |
| 1422 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1423 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1424 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 1425 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1426 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1427 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1428 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1429 | } |
| 1430 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1431 | else |
| 1432 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1433 | if (IsCubeMapTextureTarget(target) && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1434 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1435 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1436 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1439 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1440 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1441 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1442 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | int maxLevelDimension = (maxDimension >> level); |
| 1446 | if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension) |
| 1447 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1448 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1449 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1450 | } |
| 1451 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1452 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1453 | *textureFormatOut = texture->getInternalFormat(target, level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1454 | return true; |
| 1455 | } |
| 1456 | |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 1457 | static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1458 | { |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1459 | switch (mode) |
| 1460 | { |
| 1461 | case GL_POINTS: |
| 1462 | case GL_LINES: |
| 1463 | case GL_LINE_LOOP: |
| 1464 | case GL_LINE_STRIP: |
| 1465 | case GL_TRIANGLES: |
| 1466 | case GL_TRIANGLE_STRIP: |
| 1467 | case GL_TRIANGLE_FAN: |
| 1468 | break; |
| 1469 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1470 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1471 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1472 | } |
| 1473 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1474 | if (count < 0) |
| 1475 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1476 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1477 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1478 | } |
| 1479 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1480 | const State &state = context->getState(); |
| 1481 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1482 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1483 | if (state.hasMappedBuffer(GL_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1484 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1485 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1486 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1487 | } |
| 1488 | |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 1489 | if (context->getLimitations().noSeparateStencilRefsAndMasks) |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1490 | { |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 1491 | const gl::DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 1492 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 1493 | state.getStencilRef() != state.getStencilBackRef() || |
| 1494 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 1495 | { |
| 1496 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 1497 | // Section 6.10 of the WebGL 1.0 spec |
| 1498 | ERR( |
| 1499 | "This ANGLE implementation does not support separate front/back stencil " |
| 1500 | "writemasks, reference values, or stencil mask values."); |
| 1501 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1502 | return false; |
| 1503 | } |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1504 | } |
| 1505 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1506 | const gl::Framebuffer *fbo = state.getDrawFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1507 | if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1508 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1509 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1510 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1511 | } |
| 1512 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1513 | gl::Program *program = state.getProgram(); |
| 1514 | if (!program) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1515 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1516 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1517 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1518 | } |
| 1519 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1520 | if (!program->validateSamplers(NULL, context->getCaps())) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1521 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1522 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1523 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1524 | } |
| 1525 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1526 | // Uniform buffer validation |
| 1527 | for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 1528 | { |
Jamie Madill | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1529 | const gl::UniformBlock *uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1530 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
| 1531 | const gl::Buffer *uniformBuffer = state.getIndexedUniformBuffer(blockBinding); |
| 1532 | |
| 1533 | if (!uniformBuffer) |
| 1534 | { |
| 1535 | // undefined behaviour |
| 1536 | context->recordError(Error(GL_INVALID_OPERATION, "It is undefined behaviour to have a used but unbound uniform buffer.")); |
| 1537 | return false; |
| 1538 | } |
| 1539 | |
| 1540 | size_t uniformBufferSize = state.getIndexedUniformBufferSize(blockBinding); |
| 1541 | |
| 1542 | if (uniformBufferSize == 0) |
| 1543 | { |
| 1544 | // Bind the whole buffer. |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 1545 | uniformBufferSize = static_cast<size_t>(uniformBuffer->getSize()); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Jamie Madill | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1548 | if (uniformBufferSize < uniformBlock->dataSize) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1549 | { |
| 1550 | // undefined behaviour |
| 1551 | context->recordError(Error(GL_INVALID_OPERATION, "It is undefined behaviour to use a uniform buffer that is too small.")); |
| 1552 | return false; |
| 1553 | } |
| 1554 | } |
| 1555 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1556 | // No-op if zero count |
| 1557 | return (count > 0); |
| 1558 | } |
| 1559 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1560 | bool ValidateDrawArrays(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1561 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1562 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1563 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1564 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1565 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1566 | } |
| 1567 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1568 | const State &state = context->getState(); |
| 1569 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1570 | if (curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused() && |
| 1571 | curTransformFeedback->getPrimitiveMode() != mode) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1572 | { |
| 1573 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 1574 | // that does not match the current transform feedback object's draw mode (if transform feedback |
| 1575 | // is active), (3.0.2, section 2.14, pg 86) |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1576 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1577 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1578 | } |
| 1579 | |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 1580 | if (!ValidateDrawBase(context, mode, count, primcount)) |
| 1581 | { |
| 1582 | return false; |
| 1583 | } |
| 1584 | |
| 1585 | if (!ValidateDrawAttribs(context, primcount, count)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1586 | { |
| 1587 | return false; |
| 1588 | } |
| 1589 | |
| 1590 | return true; |
| 1591 | } |
| 1592 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1593 | bool ValidateDrawArraysInstanced(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1594 | { |
| 1595 | if (primcount < 0) |
| 1596 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1597 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1598 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1599 | } |
| 1600 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1601 | if (!ValidateDrawArrays(context, mode, first, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1602 | { |
| 1603 | return false; |
| 1604 | } |
| 1605 | |
| 1606 | // No-op if zero primitive count |
| 1607 | return (primcount > 0); |
| 1608 | } |
| 1609 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1610 | static bool ValidateDrawInstancedANGLE(Context *context) |
| 1611 | { |
| 1612 | // Verify there is at least one active attribute with a divisor of zero |
| 1613 | const gl::State& state = context->getState(); |
| 1614 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1615 | gl::Program *program = state.getProgram(); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1616 | |
| 1617 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 1618 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1619 | { |
| 1620 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 1621 | if (program->isAttribLocationActive(attributeIndex) && attrib.divisor == 0) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1622 | { |
| 1623 | return true; |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | context->recordError(Error(GL_INVALID_OPERATION, "ANGLE_instanced_arrays requires that at least one active attribute" |
| 1628 | "has a divisor of zero.")); |
| 1629 | return false; |
| 1630 | } |
| 1631 | |
| 1632 | bool ValidateDrawArraysInstancedANGLE(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
| 1633 | { |
| 1634 | if (!ValidateDrawInstancedANGLE(context)) |
| 1635 | { |
| 1636 | return false; |
| 1637 | } |
| 1638 | |
| 1639 | return ValidateDrawArraysInstanced(context, mode, first, count, primcount); |
| 1640 | } |
| 1641 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1642 | bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum type, |
Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame] | 1643 | const GLvoid *indices, GLsizei primcount, RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1644 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1645 | switch (type) |
| 1646 | { |
| 1647 | case GL_UNSIGNED_BYTE: |
| 1648 | case GL_UNSIGNED_SHORT: |
| 1649 | break; |
| 1650 | case GL_UNSIGNED_INT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1651 | if (!context->getExtensions().elementIndexUint) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1652 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1653 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1654 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1655 | } |
| 1656 | break; |
| 1657 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1658 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1659 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1662 | const State &state = context->getState(); |
| 1663 | |
| 1664 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1665 | if (curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1666 | { |
| 1667 | // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced |
| 1668 | // 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] | 1669 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1670 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1674 | if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1675 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1676 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1677 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1678 | } |
| 1679 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1680 | const gl::VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1681 | gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1682 | if (!indices && !elementArrayBuffer) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -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 | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1686 | } |
| 1687 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1688 | if (elementArrayBuffer) |
| 1689 | { |
| 1690 | const gl::Type &typeInfo = gl::GetTypeInfo(type); |
| 1691 | |
| 1692 | GLint64 offset = reinterpret_cast<GLint64>(indices); |
| 1693 | GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset; |
| 1694 | |
| 1695 | // check for integer overflows |
| 1696 | if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) || |
| 1697 | byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max())) |
| 1698 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1699 | context->recordError(Error(GL_OUT_OF_MEMORY)); |
| 1700 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | // Check for reading past the end of the bound buffer object |
| 1704 | if (byteCount > elementArrayBuffer->getSize()) |
| 1705 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1706 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1707 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | else if (!indices) |
| 1711 | { |
| 1712 | // Catch this programming error here |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1713 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1714 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1715 | } |
| 1716 | |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 1717 | if (!ValidateDrawBase(context, mode, count, primcount)) |
| 1718 | { |
| 1719 | return false; |
| 1720 | } |
| 1721 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1722 | // Use max index to validate if our vertex buffers are large enough for the pull. |
| 1723 | // TODO: offer fast path, with disabled index validation. |
| 1724 | // TODO: also disable index checking on back-ends that are robust to out-of-range accesses. |
| 1725 | if (elementArrayBuffer) |
| 1726 | { |
Jacek Caban | a5521de | 2014-10-01 17:23:46 +0200 | [diff] [blame] | 1727 | uintptr_t offset = reinterpret_cast<uintptr_t>(indices); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1728 | Error error = elementArrayBuffer->getIndexRange(type, static_cast<size_t>(offset), count, indexRangeOut); |
| 1729 | if (error.isError()) |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1730 | { |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1731 | context->recordError(error); |
| 1732 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1733 | } |
| 1734 | } |
| 1735 | else |
| 1736 | { |
Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame] | 1737 | *indexRangeOut = ComputeIndexRange(type, indices, count); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1738 | } |
| 1739 | |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 1740 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLsizei>(indexRangeOut->end))) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1741 | { |
| 1742 | return false; |
| 1743 | } |
| 1744 | |
| 1745 | return true; |
| 1746 | } |
| 1747 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1748 | bool ValidateDrawElementsInstanced(Context *context, |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1749 | GLenum mode, GLsizei count, GLenum type, |
| 1750 | const GLvoid *indices, GLsizei primcount, |
Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame] | 1751 | RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1752 | { |
| 1753 | if (primcount < 0) |
| 1754 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1755 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1756 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1757 | } |
| 1758 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1759 | if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1760 | { |
| 1761 | return false; |
| 1762 | } |
| 1763 | |
| 1764 | // No-op zero primitive count |
| 1765 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1766 | } |
| 1767 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1768 | bool ValidateDrawElementsInstancedANGLE(Context *context, GLenum mode, GLsizei count, GLenum type, |
Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame] | 1769 | const GLvoid *indices, GLsizei primcount, RangeUI *indexRangeOut) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1770 | { |
| 1771 | if (!ValidateDrawInstancedANGLE(context)) |
| 1772 | { |
| 1773 | return false; |
| 1774 | } |
| 1775 | |
| 1776 | return ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, indexRangeOut); |
| 1777 | } |
| 1778 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1779 | bool ValidateFramebufferTextureBase(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1780 | GLuint texture, GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1781 | { |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1782 | if (!ValidFramebufferTarget(target)) |
| 1783 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1784 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1785 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1789 | { |
| 1790 | return false; |
| 1791 | } |
| 1792 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1793 | if (texture != 0) |
| 1794 | { |
| 1795 | gl::Texture *tex = context->getTexture(texture); |
| 1796 | |
| 1797 | if (tex == NULL) |
| 1798 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1799 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1800 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | if (level < 0) |
| 1804 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1805 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1806 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1807 | } |
| 1808 | } |
| 1809 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1810 | const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1811 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1812 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1813 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1814 | { |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1815 | context->recordError(Error(GL_INVALID_OPERATION, "Cannot change default FBO's attachments")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1816 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | return true; |
| 1820 | } |
| 1821 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1822 | bool ValidateFramebufferTexture2D(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1823 | GLenum textarget, GLuint texture, GLint level) |
| 1824 | { |
Geoff Lang | 9566391 | 2015-04-02 15:54:45 -0400 | [diff] [blame] | 1825 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap extension |
| 1826 | if (context->getClientVersion() < 3 && !context->getExtensions().fboRenderMipmap && level != 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1827 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1828 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1829 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1833 | { |
| 1834 | return false; |
| 1835 | } |
| 1836 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1837 | if (texture != 0) |
| 1838 | { |
| 1839 | gl::Texture *tex = context->getTexture(texture); |
| 1840 | ASSERT(tex); |
| 1841 | |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1842 | const gl::Caps &caps = context->getCaps(); |
| 1843 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1844 | switch (textarget) |
| 1845 | { |
| 1846 | case GL_TEXTURE_2D: |
| 1847 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1848 | if (level > gl::log2(caps.max2DTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1849 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1850 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1851 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1852 | } |
| 1853 | if (tex->getTarget() != GL_TEXTURE_2D) |
| 1854 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1855 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1856 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1857 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1858 | } |
| 1859 | break; |
| 1860 | |
| 1861 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1862 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1863 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1864 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1865 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1866 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1867 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1868 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1869 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1870 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1871 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1872 | } |
| 1873 | if (tex->getTarget() != GL_TEXTURE_CUBE_MAP) |
| 1874 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1875 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1876 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1877 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1878 | } |
| 1879 | break; |
| 1880 | |
| 1881 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1882 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1883 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1884 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1885 | |
| 1886 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(textarget, level)); |
| 1887 | if (internalFormatInfo.compressed) |
| 1888 | { |
| 1889 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1890 | return false; |
| 1891 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1892 | } |
| 1893 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1894 | return true; |
| 1895 | } |
| 1896 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1897 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1898 | { |
| 1899 | if (program == 0) |
| 1900 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1901 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1902 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1903 | } |
| 1904 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame^] | 1905 | gl::Program *programObject = GetValidProgram(context, program); |
| 1906 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 1907 | { |
| 1908 | return false; |
| 1909 | } |
| 1910 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1911 | if (!programObject || !programObject->isLinked()) |
| 1912 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1913 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1914 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1915 | } |
| 1916 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1917 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1918 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1919 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1920 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1921 | } |
| 1922 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1923 | return true; |
| 1924 | } |
| 1925 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1926 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat* params) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1927 | { |
| 1928 | return ValidateGetUniformBase(context, program, location); |
| 1929 | } |
| 1930 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1931 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1932 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1933 | return ValidateGetUniformBase(context, program, location); |
| 1934 | } |
| 1935 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1936 | static bool ValidateSizedGetUniform(Context *context, GLuint program, GLint location, GLsizei bufSize) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1937 | { |
| 1938 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1939 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1940 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1941 | } |
| 1942 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 1943 | gl::Program *programObject = context->getProgram(program); |
| 1944 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1945 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1946 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 61b8dd9 | 2015-09-09 19:04:04 +0000 | [diff] [blame] | 1947 | LinkedUniform *uniform = programObject->getUniformByLocation(location); |
| 1948 | size_t requiredBytes = VariableExternalSize(uniform->type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1949 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1950 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1951 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1952 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | return true; |
| 1956 | } |
| 1957 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1958 | bool ValidateGetnUniformfvEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1959 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1960 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1961 | } |
| 1962 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1963 | bool ValidateGetnUniformivEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params) |
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 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1966 | } |
| 1967 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1968 | bool ValidateDiscardFramebufferBase(Context *context, GLenum target, GLsizei numAttachments, |
| 1969 | const GLenum *attachments, bool defaultFramebuffer) |
| 1970 | { |
| 1971 | if (numAttachments < 0) |
| 1972 | { |
| 1973 | context->recordError(Error(GL_INVALID_VALUE, "numAttachments must not be less than zero")); |
| 1974 | return false; |
| 1975 | } |
| 1976 | |
| 1977 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 1978 | { |
| 1979 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15) |
| 1980 | { |
| 1981 | if (defaultFramebuffer) |
| 1982 | { |
| 1983 | context->recordError(Error(GL_INVALID_ENUM, "Invalid attachment when the default framebuffer is bound")); |
| 1984 | return false; |
| 1985 | } |
| 1986 | |
| 1987 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 1988 | { |
| 1989 | context->recordError(Error(GL_INVALID_OPERATION, |
| 1990 | "Requested color attachment is greater than the maximum supported color attachments")); |
| 1991 | return false; |
| 1992 | } |
| 1993 | } |
| 1994 | else |
| 1995 | { |
| 1996 | switch (attachments[i]) |
| 1997 | { |
| 1998 | case GL_DEPTH_ATTACHMENT: |
| 1999 | case GL_STENCIL_ATTACHMENT: |
| 2000 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 2001 | if (defaultFramebuffer) |
| 2002 | { |
| 2003 | context->recordError(Error(GL_INVALID_ENUM, "Invalid attachment when the default framebuffer is bound")); |
| 2004 | return false; |
| 2005 | } |
| 2006 | break; |
| 2007 | case GL_COLOR: |
| 2008 | case GL_DEPTH: |
| 2009 | case GL_STENCIL: |
| 2010 | if (!defaultFramebuffer) |
| 2011 | { |
| 2012 | context->recordError(Error(GL_INVALID_ENUM, "Invalid attachment when the default framebuffer is not bound")); |
| 2013 | return false; |
| 2014 | } |
| 2015 | break; |
| 2016 | default: |
| 2017 | context->recordError(Error(GL_INVALID_ENUM, "Invalid attachment")); |
| 2018 | return false; |
| 2019 | } |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | return true; |
| 2024 | } |
| 2025 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 2026 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 2027 | { |
| 2028 | // Note that debug marker calls must not set error state |
| 2029 | |
| 2030 | if (length < 0) |
| 2031 | { |
| 2032 | return false; |
| 2033 | } |
| 2034 | |
| 2035 | if (marker == nullptr) |
| 2036 | { |
| 2037 | return false; |
| 2038 | } |
| 2039 | |
| 2040 | return true; |
| 2041 | } |
| 2042 | |
| 2043 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 2044 | { |
| 2045 | // Note that debug marker calls must not set error state |
| 2046 | |
| 2047 | if (length < 0) |
| 2048 | { |
| 2049 | return false; |
| 2050 | } |
| 2051 | |
| 2052 | if (length > 0 && marker == nullptr) |
| 2053 | { |
| 2054 | return false; |
| 2055 | } |
| 2056 | |
| 2057 | return true; |
| 2058 | } |
| 2059 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 2060 | bool ValidateEGLImageTargetTexture2DOES(Context *context, |
| 2061 | egl::Display *display, |
| 2062 | GLenum target, |
| 2063 | egl::Image *image) |
| 2064 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2065 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 2066 | { |
| 2067 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 2068 | return false; |
| 2069 | } |
| 2070 | |
| 2071 | switch (target) |
| 2072 | { |
| 2073 | case GL_TEXTURE_2D: |
| 2074 | break; |
| 2075 | |
| 2076 | default: |
| 2077 | context->recordError(Error(GL_INVALID_ENUM, "invalid texture target.")); |
| 2078 | return false; |
| 2079 | } |
| 2080 | |
| 2081 | if (!display->isValidImage(image)) |
| 2082 | { |
| 2083 | context->recordError(Error(GL_INVALID_VALUE, "EGL image is not valid.")); |
| 2084 | return false; |
| 2085 | } |
| 2086 | |
| 2087 | if (image->getSamples() > 0) |
| 2088 | { |
| 2089 | context->recordError(Error(GL_INVALID_OPERATION, |
| 2090 | "cannot create a 2D texture from a multisampled EGL image.")); |
| 2091 | return false; |
| 2092 | } |
| 2093 | |
| 2094 | const TextureCaps &textureCaps = context->getTextureCaps().get(image->getInternalFormat()); |
| 2095 | if (!textureCaps.texturable) |
| 2096 | { |
| 2097 | context->recordError(Error(GL_INVALID_OPERATION, |
| 2098 | "EGL image internal format is not supported as a texture.")); |
| 2099 | return false; |
| 2100 | } |
| 2101 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 2102 | return true; |
| 2103 | } |
| 2104 | |
| 2105 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
| 2106 | egl::Display *display, |
| 2107 | GLenum target, |
| 2108 | egl::Image *image) |
| 2109 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 2110 | if (!context->getExtensions().eglImage) |
| 2111 | { |
| 2112 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 2113 | return false; |
| 2114 | } |
| 2115 | |
| 2116 | switch (target) |
| 2117 | { |
| 2118 | case GL_RENDERBUFFER: |
| 2119 | break; |
| 2120 | |
| 2121 | default: |
| 2122 | context->recordError(Error(GL_INVALID_ENUM, "invalid renderbuffer target.")); |
| 2123 | return false; |
| 2124 | } |
| 2125 | |
| 2126 | if (!display->isValidImage(image)) |
| 2127 | { |
| 2128 | context->recordError(Error(GL_INVALID_VALUE, "EGL image is not valid.")); |
| 2129 | return false; |
| 2130 | } |
| 2131 | |
| 2132 | const TextureCaps &textureCaps = context->getTextureCaps().get(image->getInternalFormat()); |
| 2133 | if (!textureCaps.renderable) |
| 2134 | { |
| 2135 | context->recordError(Error( |
| 2136 | GL_INVALID_OPERATION, "EGL image internal format is not supported as a renderbuffer.")); |
| 2137 | return false; |
| 2138 | } |
| 2139 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 2140 | return true; |
| 2141 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2142 | } |