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