Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | #include "precompiled.h" |
| 2 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 3 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // validationES.h: Validation functions for generic OpenGL ES entry point parameters |
| 9 | |
| 10 | #include "libGLESv2/validationES.h" |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 11 | #include "libGLESv2/validationES2.h" |
| 12 | #include "libGLESv2/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 13 | #include "libGLESv2/Context.h" |
| 14 | #include "libGLESv2/Texture.h" |
| 15 | #include "libGLESv2/Framebuffer.h" |
| 16 | #include "libGLESv2/Renderbuffer.h" |
| 17 | #include "libGLESv2/formatutils.h" |
| 18 | #include "libGLESv2/main.h" |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 19 | #include "libGLESv2/Query.h" |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 20 | #include "libGLESv2/ProgramBinary.h" |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 21 | #include "libGLESv2/TransformFeedback.h" |
Jamie Madill | 9efa581 | 2014-06-20 13:21:24 -0400 | [diff] [blame] | 22 | #include "libGLESv2/VertexArray.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 23 | |
| 24 | #include "common/mathutil.h" |
| 25 | #include "common/utilities.h" |
| 26 | |
| 27 | namespace gl |
| 28 | { |
| 29 | |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 30 | bool ValidCap(const Context *context, GLenum cap) |
| 31 | { |
| 32 | switch (cap) |
| 33 | { |
| 34 | case GL_CULL_FACE: |
| 35 | case GL_POLYGON_OFFSET_FILL: |
| 36 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 37 | case GL_SAMPLE_COVERAGE: |
| 38 | case GL_SCISSOR_TEST: |
| 39 | case GL_STENCIL_TEST: |
| 40 | case GL_DEPTH_TEST: |
| 41 | case GL_BLEND: |
| 42 | case GL_DITHER: |
| 43 | return true; |
| 44 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 45 | case GL_RASTERIZER_DISCARD: |
| 46 | return (context->getClientVersion() >= 3); |
| 47 | default: |
| 48 | return false; |
| 49 | } |
| 50 | } |
| 51 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 52 | bool ValidTextureTarget(const Context *context, GLenum target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 53 | { |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 54 | switch (target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 55 | { |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 56 | case GL_TEXTURE_2D: |
| 57 | case GL_TEXTURE_CUBE_MAP: |
| 58 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 59 | |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 60 | case GL_TEXTURE_3D: |
| 61 | case GL_TEXTURE_2D_ARRAY: |
| 62 | return (context->getClientVersion() >= 3); |
| 63 | |
| 64 | default: |
| 65 | return false; |
| 66 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 69 | // This function differs from ValidTextureTarget in that the target must be |
| 70 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 71 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 72 | // Note: duplicate of IsInternalTextureTarget |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 73 | bool ValidTexture2DDestinationTarget(const Context *context, GLenum target) |
| 74 | { |
| 75 | switch (target) |
| 76 | { |
| 77 | case GL_TEXTURE_2D: |
| 78 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 79 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 80 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 81 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 82 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 83 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 84 | return true; |
| 85 | case GL_TEXTURE_2D_ARRAY: |
| 86 | case GL_TEXTURE_3D: |
| 87 | return (context->getClientVersion() >= 3); |
| 88 | default: |
| 89 | return false; |
| 90 | } |
| 91 | } |
| 92 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 93 | bool ValidFramebufferTarget(GLenum target) |
| 94 | { |
| 95 | META_ASSERT(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER); |
| 96 | |
| 97 | switch (target) |
| 98 | { |
| 99 | case GL_FRAMEBUFFER: return true; |
| 100 | case GL_READ_FRAMEBUFFER: return true; |
| 101 | case GL_DRAW_FRAMEBUFFER: return true; |
| 102 | default: return false; |
| 103 | } |
| 104 | } |
| 105 | |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 106 | bool ValidBufferTarget(const Context *context, GLenum target) |
| 107 | { |
| 108 | switch (target) |
| 109 | { |
| 110 | case GL_ARRAY_BUFFER: |
| 111 | case GL_ELEMENT_ARRAY_BUFFER: |
| 112 | return true; |
| 113 | |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 114 | case GL_PIXEL_PACK_BUFFER: |
| 115 | case GL_PIXEL_UNPACK_BUFFER: |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 116 | return context->getCaps().extensions.pixelBufferObject; |
Shannon Woods | 158c438 | 2014-05-06 13:00:07 -0400 | [diff] [blame] | 117 | |
Shannon Woods | b380174 | 2014-03-27 14:59:19 -0400 | [diff] [blame] | 118 | case GL_COPY_READ_BUFFER: |
| 119 | case GL_COPY_WRITE_BUFFER: |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 120 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 121 | case GL_UNIFORM_BUFFER: |
| 122 | return (context->getClientVersion() >= 3); |
| 123 | |
| 124 | default: |
| 125 | return false; |
| 126 | } |
| 127 | } |
| 128 | |
Jamie Madill | 70656a6 | 2014-03-05 15:01:26 -0500 | [diff] [blame] | 129 | bool ValidBufferParameter(const Context *context, GLenum pname) |
| 130 | { |
| 131 | switch (pname) |
| 132 | { |
| 133 | case GL_BUFFER_USAGE: |
| 134 | case GL_BUFFER_SIZE: |
| 135 | return true; |
| 136 | |
| 137 | // GL_BUFFER_MAP_POINTER is a special case, and may only be |
| 138 | // queried with GetBufferPointerv |
| 139 | case GL_BUFFER_ACCESS_FLAGS: |
| 140 | case GL_BUFFER_MAPPED: |
| 141 | case GL_BUFFER_MAP_OFFSET: |
| 142 | case GL_BUFFER_MAP_LENGTH: |
| 143 | return (context->getClientVersion() >= 3); |
| 144 | |
| 145 | default: |
| 146 | return false; |
| 147 | } |
| 148 | } |
| 149 | |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 150 | bool ValidMipLevel(const Context *context, GLenum target, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 151 | { |
| 152 | int maxLevel = 0; |
| 153 | switch (target) |
| 154 | { |
| 155 | case GL_TEXTURE_2D: maxLevel = context->getMaximum2DTextureLevel(); break; |
| 156 | case GL_TEXTURE_CUBE_MAP: |
| 157 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 158 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 159 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 160 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 161 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 162 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: maxLevel = context->getMaximumCubeTextureLevel(); break; |
| 163 | case GL_TEXTURE_3D: maxLevel = context->getMaximum3DTextureLevel(); break; |
| 164 | case GL_TEXTURE_2D_ARRAY: maxLevel = context->getMaximum2DArrayTextureLevel(); break; |
| 165 | default: UNREACHABLE(); |
| 166 | } |
| 167 | |
| 168 | return level < maxLevel; |
| 169 | } |
| 170 | |
| 171 | bool ValidImageSize(const gl::Context *context, GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) |
| 172 | { |
| 173 | if (level < 0 || width < 0 || height < 0 || depth < 0) |
| 174 | { |
| 175 | return false; |
| 176 | } |
| 177 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 178 | if (!context->getCaps().extensions.textureNPOT && (level != 0 || !gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 179 | { |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | if (!ValidMipLevel(context, target, level)) |
| 184 | { |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | return true; |
| 189 | } |
| 190 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 191 | bool ValidCompressedImageSize(const gl::Context *context, GLenum internalFormat, GLsizei width, GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 192 | { |
| 193 | GLuint clientVersion = context->getClientVersion(); |
| 194 | if (!IsFormatCompressed(internalFormat, clientVersion)) |
| 195 | { |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | GLint blockWidth = GetCompressedBlockWidth(internalFormat, clientVersion); |
| 200 | GLint blockHeight = GetCompressedBlockHeight(internalFormat, clientVersion); |
| 201 | if (width < 0 || (width > blockWidth && width % blockWidth != 0) || |
| 202 | height < 0 || (height > blockHeight && height % blockHeight != 0)) |
| 203 | { |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | return true; |
| 208 | } |
| 209 | |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 210 | bool ValidQueryType(const Context *context, GLenum queryType) |
| 211 | { |
| 212 | META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT); |
| 213 | META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT); |
| 214 | |
| 215 | switch (queryType) |
| 216 | { |
| 217 | case GL_ANY_SAMPLES_PASSED: |
| 218 | case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: |
| 219 | return true; |
| 220 | case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: |
| 221 | return (context->getClientVersion() >= 3); |
| 222 | default: |
| 223 | return false; |
| 224 | } |
| 225 | } |
| 226 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 227 | bool ValidProgram(const Context *context, GLuint id) |
| 228 | { |
| 229 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the |
| 230 | // error INVALID_VALUE if the provided name is not the name of either a shader or program object and |
| 231 | // INVALID_OPERATION if the provided name identifies an object that is not the expected type." |
| 232 | |
| 233 | if (context->getProgram(id) != NULL) |
| 234 | { |
| 235 | return true; |
| 236 | } |
| 237 | else if (context->getShader(id) != NULL) |
| 238 | { |
| 239 | // ID is the wrong type |
| 240 | return gl::error(GL_INVALID_OPERATION, false); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | // No shader/program object has this ID |
| 245 | return gl::error(GL_INVALID_VALUE, false); |
| 246 | } |
| 247 | } |
| 248 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 249 | bool ValidateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 250 | GLenum internalformat, GLsizei width, GLsizei height, |
| 251 | bool angleExtension) |
| 252 | { |
| 253 | switch (target) |
| 254 | { |
| 255 | case GL_RENDERBUFFER: |
| 256 | break; |
| 257 | default: |
| 258 | return gl::error(GL_INVALID_ENUM, false); |
| 259 | } |
| 260 | |
| 261 | if (width < 0 || height < 0 || samples < 0) |
| 262 | { |
| 263 | return gl::error(GL_INVALID_VALUE, false); |
| 264 | } |
| 265 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 266 | const gl::Caps &caps = context->getCaps(); |
| 267 | if (!gl::IsValidInternalFormat(internalformat, caps.extensions, context->getClientVersion())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 268 | { |
| 269 | return gl::error(GL_INVALID_ENUM, false); |
| 270 | } |
| 271 | |
| 272 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 273 | // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains |
| 274 | // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the |
| 275 | // internal format must be sized and not an integer format if samples is greater than zero. |
| 276 | if (!gl::IsSizedInternalFormat(internalformat, context->getClientVersion())) |
| 277 | { |
| 278 | return gl::error(GL_INVALID_ENUM, false); |
| 279 | } |
| 280 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 281 | GLenum componentType = gl::GetComponentType(internalformat, context->getClientVersion()); |
| 282 | if ((componentType == GL_UNSIGNED_INT || componentType == GL_INT) && samples > 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 283 | { |
| 284 | return gl::error(GL_INVALID_OPERATION, false); |
| 285 | } |
| 286 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 287 | const TextureCaps &formatCaps = caps.textureCaps.get(internalformat); |
| 288 | if (!formatCaps.colorRendering && !formatCaps.depthRendering && !formatCaps.stencilRendering) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 289 | { |
| 290 | return gl::error(GL_INVALID_ENUM, false); |
| 291 | } |
| 292 | |
| 293 | if (std::max(width, height) > context->getMaximumRenderbufferDimension()) |
| 294 | { |
| 295 | return gl::error(GL_INVALID_VALUE, false); |
| 296 | } |
| 297 | |
| 298 | // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal |
| 299 | // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2) |
| 300 | // states that samples must be less than or equal to the maximum samples for the specified |
| 301 | // internal format. |
| 302 | if (angleExtension) |
| 303 | { |
| 304 | if (samples > context->getMaxSupportedSamples()) |
| 305 | { |
| 306 | return gl::error(GL_INVALID_VALUE, false); |
| 307 | } |
| 308 | } |
| 309 | else |
| 310 | { |
| 311 | if (samples > context->getMaxSupportedFormatSamples(internalformat)) |
| 312 | { |
| 313 | return gl::error(GL_INVALID_VALUE, false); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | GLuint handle = context->getRenderbufferHandle(); |
| 318 | if (handle == 0) |
| 319 | { |
| 320 | return gl::error(GL_INVALID_OPERATION, false); |
| 321 | } |
| 322 | |
| 323 | return true; |
| 324 | } |
| 325 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 326 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment, |
| 327 | GLenum renderbuffertarget, GLuint renderbuffer) |
| 328 | { |
| 329 | gl::Framebuffer *framebuffer = context->getTargetFramebuffer(target); |
| 330 | GLuint framebufferHandle = context->getTargetFramebufferHandle(target); |
| 331 | |
| 332 | if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0)) |
| 333 | { |
| 334 | return gl::error(GL_INVALID_OPERATION, false); |
| 335 | } |
| 336 | |
| 337 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 338 | { |
| 339 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
| 340 | |
| 341 | if (colorAttachment >= context->getMaximumRenderTargets()) |
| 342 | { |
| 343 | return gl::error(GL_INVALID_VALUE, false); |
| 344 | } |
| 345 | } |
| 346 | else |
| 347 | { |
| 348 | switch (attachment) |
| 349 | { |
| 350 | case GL_DEPTH_ATTACHMENT: |
| 351 | break; |
| 352 | case GL_STENCIL_ATTACHMENT: |
| 353 | break; |
| 354 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 355 | if (context->getClientVersion() < 3) |
| 356 | { |
| 357 | return gl::error(GL_INVALID_ENUM, false); |
| 358 | } |
| 359 | break; |
| 360 | default: |
| 361 | return gl::error(GL_INVALID_ENUM, false); |
| 362 | } |
| 363 | } |
| 364 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 365 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 366 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 367 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 368 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 369 | if (renderbuffer != 0) |
| 370 | { |
| 371 | if (!context->getRenderbuffer(renderbuffer)) |
| 372 | { |
| 373 | return gl::error(GL_INVALID_OPERATION, false); |
| 374 | } |
| 375 | } |
| 376 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 377 | return true; |
| 378 | } |
| 379 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 380 | static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer, |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 381 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 382 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1) |
| 383 | { |
| 384 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || |
| 385 | dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() || |
| 386 | srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight()) |
| 387 | { |
| 388 | return true; |
| 389 | } |
| 390 | else if (context->isScissorTestEnabled()) |
| 391 | { |
| 392 | int scissorX, scissorY, scissorWidth, scissorHeight; |
| 393 | context->getScissorParams(&scissorX, &scissorY, &scissorWidth, &scissorHeight); |
| 394 | |
| 395 | return scissorX > 0 || scissorY > 0 || |
| 396 | scissorWidth < writeBuffer->getWidth() || |
| 397 | scissorHeight < writeBuffer->getHeight(); |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | return false; |
| 402 | } |
| 403 | } |
| 404 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 405 | 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] | 406 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, |
| 407 | GLenum filter, bool fromAngleExtension) |
| 408 | { |
| 409 | switch (filter) |
| 410 | { |
| 411 | case GL_NEAREST: |
| 412 | break; |
| 413 | case GL_LINEAR: |
| 414 | if (fromAngleExtension) |
| 415 | { |
| 416 | return gl::error(GL_INVALID_ENUM, false); |
| 417 | } |
| 418 | break; |
| 419 | default: |
| 420 | return gl::error(GL_INVALID_ENUM, false); |
| 421 | } |
| 422 | |
| 423 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 424 | { |
| 425 | return gl::error(GL_INVALID_VALUE, false); |
| 426 | } |
| 427 | |
| 428 | if (mask == 0) |
| 429 | { |
| 430 | // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no |
| 431 | // buffers are copied. |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)) |
| 436 | { |
| 437 | ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation."); |
| 438 | return gl::error(GL_INVALID_OPERATION, false); |
| 439 | } |
| 440 | |
| 441 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 442 | // color buffer, leaving only nearest being unfiltered from above |
| 443 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 444 | { |
| 445 | return gl::error(GL_INVALID_OPERATION, false); |
| 446 | } |
| 447 | |
| 448 | if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle()) |
| 449 | { |
| 450 | if (fromAngleExtension) |
| 451 | { |
| 452 | ERR("Blits with the same source and destination framebuffer are not supported by this " |
| 453 | "implementation."); |
| 454 | } |
| 455 | return gl::error(GL_INVALID_OPERATION, false); |
| 456 | } |
| 457 | |
| 458 | gl::Framebuffer *readFramebuffer = context->getReadFramebuffer(); |
| 459 | gl::Framebuffer *drawFramebuffer = context->getDrawFramebuffer(); |
| 460 | if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE || |
| 461 | !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 462 | { |
| 463 | return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
| 464 | } |
| 465 | |
| 466 | if (drawFramebuffer->getSamples() != 0) |
| 467 | { |
| 468 | return gl::error(GL_INVALID_OPERATION, false); |
| 469 | } |
| 470 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 471 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 472 | |
| 473 | GLuint clientVersion = context->getClientVersion(); |
| 474 | |
| 475 | if (mask & GL_COLOR_BUFFER_BIT) |
| 476 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 477 | gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 478 | gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 479 | |
| 480 | if (readColorBuffer && drawColorBuffer) |
| 481 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 482 | GLenum readInternalFormat = readColorBuffer->getActualFormat(); |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 483 | GLenum readComponentType = gl::GetComponentType(readInternalFormat, clientVersion); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 484 | |
| 485 | for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++) |
| 486 | { |
| 487 | if (drawFramebuffer->isEnabledColorAttachment(i)) |
| 488 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 489 | GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat(); |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 490 | GLenum drawComponentType = gl::GetComponentType(drawInternalFormat, clientVersion); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 491 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 492 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 493 | // 1) If the read buffer is fixed point format, the draw buffer must be as well |
| 494 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well |
| 495 | // 3) If the read buffer is a signed integer format, the draw buffer must be as well |
| 496 | if ( (readComponentType == GL_UNSIGNED_NORMALIZED || readComponentType == GL_SIGNED_NORMALIZED) && |
| 497 | !(drawComponentType == GL_UNSIGNED_NORMALIZED || drawComponentType == GL_SIGNED_NORMALIZED)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 498 | { |
| 499 | return gl::error(GL_INVALID_OPERATION, false); |
| 500 | } |
| 501 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 502 | if (readComponentType == GL_UNSIGNED_INT && drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 503 | { |
| 504 | return gl::error(GL_INVALID_OPERATION, false); |
| 505 | } |
| 506 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 507 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 508 | { |
| 509 | return gl::error(GL_INVALID_OPERATION, false); |
| 510 | } |
| 511 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 512 | if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 513 | { |
| 514 | return gl::error(GL_INVALID_OPERATION, false); |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 519 | if ((readComponentType == GL_INT || readComponentType == GL_UNSIGNED_INT) && filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 520 | { |
| 521 | return gl::error(GL_INVALID_OPERATION, false); |
| 522 | } |
| 523 | |
| 524 | if (fromAngleExtension) |
| 525 | { |
| 526 | const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType(); |
| 527 | if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER) |
| 528 | { |
| 529 | return gl::error(GL_INVALID_OPERATION, false); |
| 530 | } |
| 531 | |
| 532 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 533 | { |
| 534 | if (drawFramebuffer->isEnabledColorAttachment(colorAttachment)) |
| 535 | { |
| 536 | if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D && |
| 537 | drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER) |
| 538 | { |
| 539 | return gl::error(GL_INVALID_OPERATION, false); |
| 540 | } |
| 541 | |
| 542 | if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat()) |
| 543 | { |
| 544 | return gl::error(GL_INVALID_OPERATION, false); |
| 545 | } |
| 546 | } |
| 547 | } |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 548 | if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer, |
| 549 | srcX0, srcY0, srcX1, srcY1, |
| 550 | dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 551 | { |
| 552 | return gl::error(GL_INVALID_OPERATION, false); |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 559 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 560 | gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer(); |
| 561 | gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 562 | |
| 563 | if (readDepthBuffer && drawDepthBuffer) |
| 564 | { |
| 565 | if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat()) |
| 566 | { |
| 567 | return gl::error(GL_INVALID_OPERATION, false); |
| 568 | } |
| 569 | |
| 570 | if (readDepthBuffer->getSamples() > 0 && !sameBounds) |
| 571 | { |
| 572 | return gl::error(GL_INVALID_OPERATION, false); |
| 573 | } |
| 574 | |
| 575 | if (fromAngleExtension) |
| 576 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 577 | if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer, |
| 578 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 579 | { |
| 580 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
| 581 | return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted |
| 582 | } |
| 583 | |
| 584 | if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0) |
| 585 | { |
| 586 | return gl::error(GL_INVALID_OPERATION, false); |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 593 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 594 | gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer(); |
| 595 | gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 596 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 597 | if (readStencilBuffer && drawStencilBuffer) |
| 598 | { |
| 599 | if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat()) |
| 600 | { |
| 601 | return gl::error(GL_INVALID_OPERATION, false); |
| 602 | } |
| 603 | |
| 604 | if (readStencilBuffer->getSamples() > 0 && !sameBounds) |
| 605 | { |
| 606 | return gl::error(GL_INVALID_OPERATION, false); |
| 607 | } |
| 608 | |
| 609 | if (fromAngleExtension) |
| 610 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 611 | if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer, |
| 612 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 613 | { |
| 614 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
| 615 | return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted |
| 616 | } |
| 617 | |
| 618 | if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0) |
| 619 | { |
| 620 | return gl::error(GL_INVALID_OPERATION, false); |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | return true; |
| 627 | } |
| 628 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 629 | bool ValidateGetVertexAttribParameters(GLenum pname, int clientVersion) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 630 | { |
| 631 | switch (pname) |
| 632 | { |
| 633 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 634 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 635 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 636 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 637 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 638 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 639 | case GL_CURRENT_VERTEX_ATTRIB: |
| 640 | return true; |
| 641 | |
| 642 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 643 | // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses |
| 644 | // the same constant. |
| 645 | META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE); |
| 646 | return true; |
| 647 | |
| 648 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 649 | return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false)); |
| 650 | |
| 651 | default: |
| 652 | return gl::error(GL_INVALID_ENUM, false); |
| 653 | } |
| 654 | } |
| 655 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 656 | bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 657 | { |
| 658 | switch (pname) |
| 659 | { |
| 660 | case GL_TEXTURE_WRAP_R: |
| 661 | case GL_TEXTURE_SWIZZLE_R: |
| 662 | case GL_TEXTURE_SWIZZLE_G: |
| 663 | case GL_TEXTURE_SWIZZLE_B: |
| 664 | case GL_TEXTURE_SWIZZLE_A: |
| 665 | case GL_TEXTURE_BASE_LEVEL: |
| 666 | case GL_TEXTURE_MAX_LEVEL: |
| 667 | case GL_TEXTURE_COMPARE_MODE: |
| 668 | case GL_TEXTURE_COMPARE_FUNC: |
| 669 | case GL_TEXTURE_MIN_LOD: |
| 670 | case GL_TEXTURE_MAX_LOD: |
| 671 | if (context->getClientVersion() < 3) |
| 672 | { |
| 673 | return gl::error(GL_INVALID_ENUM, false); |
| 674 | } |
| 675 | break; |
| 676 | |
| 677 | default: break; |
| 678 | } |
| 679 | |
| 680 | switch (pname) |
| 681 | { |
| 682 | case GL_TEXTURE_WRAP_S: |
| 683 | case GL_TEXTURE_WRAP_T: |
| 684 | case GL_TEXTURE_WRAP_R: |
| 685 | switch (param) |
| 686 | { |
| 687 | case GL_REPEAT: |
| 688 | case GL_CLAMP_TO_EDGE: |
| 689 | case GL_MIRRORED_REPEAT: |
| 690 | return true; |
| 691 | default: |
| 692 | return gl::error(GL_INVALID_ENUM, false); |
| 693 | } |
| 694 | |
| 695 | case GL_TEXTURE_MIN_FILTER: |
| 696 | switch (param) |
| 697 | { |
| 698 | case GL_NEAREST: |
| 699 | case GL_LINEAR: |
| 700 | case GL_NEAREST_MIPMAP_NEAREST: |
| 701 | case GL_LINEAR_MIPMAP_NEAREST: |
| 702 | case GL_NEAREST_MIPMAP_LINEAR: |
| 703 | case GL_LINEAR_MIPMAP_LINEAR: |
| 704 | return true; |
| 705 | default: |
| 706 | return gl::error(GL_INVALID_ENUM, false); |
| 707 | } |
| 708 | break; |
| 709 | |
| 710 | case GL_TEXTURE_MAG_FILTER: |
| 711 | switch (param) |
| 712 | { |
| 713 | case GL_NEAREST: |
| 714 | case GL_LINEAR: |
| 715 | return true; |
| 716 | default: |
| 717 | return gl::error(GL_INVALID_ENUM, false); |
| 718 | } |
| 719 | break; |
| 720 | |
| 721 | case GL_TEXTURE_USAGE_ANGLE: |
| 722 | switch (param) |
| 723 | { |
| 724 | case GL_NONE: |
| 725 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 726 | return true; |
| 727 | default: |
| 728 | return gl::error(GL_INVALID_ENUM, false); |
| 729 | } |
| 730 | break; |
| 731 | |
| 732 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 733 | if (!context->getCaps().extensions.textureFilterAnisotropic) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 734 | { |
| 735 | return gl::error(GL_INVALID_ENUM, false); |
| 736 | } |
| 737 | |
| 738 | // we assume the parameter passed to this validation method is truncated, not rounded |
| 739 | if (param < 1) |
| 740 | { |
| 741 | return gl::error(GL_INVALID_VALUE, false); |
| 742 | } |
| 743 | return true; |
| 744 | |
| 745 | case GL_TEXTURE_MIN_LOD: |
| 746 | case GL_TEXTURE_MAX_LOD: |
| 747 | // any value is permissible |
| 748 | return true; |
| 749 | |
| 750 | case GL_TEXTURE_COMPARE_MODE: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 751 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 752 | switch (param) |
| 753 | { |
| 754 | case GL_NONE: |
| 755 | case GL_COMPARE_REF_TO_TEXTURE: |
| 756 | return true; |
| 757 | default: |
| 758 | return gl::error(GL_INVALID_ENUM, false); |
| 759 | } |
| 760 | break; |
| 761 | |
| 762 | case GL_TEXTURE_COMPARE_FUNC: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 763 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 764 | switch (param) |
| 765 | { |
| 766 | case GL_LEQUAL: |
| 767 | case GL_GEQUAL: |
| 768 | case GL_LESS: |
| 769 | case GL_GREATER: |
| 770 | case GL_EQUAL: |
| 771 | case GL_NOTEQUAL: |
| 772 | case GL_ALWAYS: |
| 773 | case GL_NEVER: |
| 774 | return true; |
| 775 | default: |
| 776 | return gl::error(GL_INVALID_ENUM, false); |
| 777 | } |
| 778 | break; |
| 779 | |
| 780 | case GL_TEXTURE_SWIZZLE_R: |
| 781 | case GL_TEXTURE_SWIZZLE_G: |
| 782 | case GL_TEXTURE_SWIZZLE_B: |
| 783 | case GL_TEXTURE_SWIZZLE_A: |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 784 | switch (param) |
| 785 | { |
| 786 | case GL_RED: |
| 787 | case GL_GREEN: |
| 788 | case GL_BLUE: |
| 789 | case GL_ALPHA: |
| 790 | case GL_ZERO: |
| 791 | case GL_ONE: |
| 792 | return true; |
| 793 | default: |
| 794 | return gl::error(GL_INVALID_ENUM, false); |
| 795 | } |
| 796 | break; |
| 797 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 798 | case GL_TEXTURE_BASE_LEVEL: |
| 799 | case GL_TEXTURE_MAX_LEVEL: |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 800 | if (param < 0) |
| 801 | { |
| 802 | return gl::error(GL_INVALID_VALUE, false); |
| 803 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 804 | return true; |
| 805 | |
| 806 | default: |
| 807 | return gl::error(GL_INVALID_ENUM, false); |
| 808 | } |
| 809 | } |
| 810 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 811 | bool ValidateSamplerObjectParameter(GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 812 | { |
| 813 | switch (pname) |
| 814 | { |
| 815 | case GL_TEXTURE_MIN_FILTER: |
| 816 | case GL_TEXTURE_MAG_FILTER: |
| 817 | case GL_TEXTURE_WRAP_S: |
| 818 | case GL_TEXTURE_WRAP_T: |
| 819 | case GL_TEXTURE_WRAP_R: |
| 820 | case GL_TEXTURE_MIN_LOD: |
| 821 | case GL_TEXTURE_MAX_LOD: |
| 822 | case GL_TEXTURE_COMPARE_MODE: |
| 823 | case GL_TEXTURE_COMPARE_FUNC: |
| 824 | return true; |
| 825 | |
| 826 | default: |
| 827 | return gl::error(GL_INVALID_ENUM, false); |
| 828 | } |
| 829 | } |
| 830 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 831 | bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height, |
| 832 | GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels) |
| 833 | { |
| 834 | gl::Framebuffer *framebuffer = context->getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 835 | ASSERT(framebuffer); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 836 | |
| 837 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 838 | { |
| 839 | return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
| 840 | } |
| 841 | |
| 842 | if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0) |
| 843 | { |
| 844 | return gl::error(GL_INVALID_OPERATION, false); |
| 845 | } |
| 846 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 847 | if (!framebuffer->getReadColorbuffer()) |
| 848 | { |
| 849 | return gl::error(GL_INVALID_OPERATION, false); |
| 850 | } |
| 851 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 852 | GLenum currentInternalFormat, currentFormat, currentType; |
| 853 | int clientVersion = context->getClientVersion(); |
| 854 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 855 | context->getCurrentReadFormatType(¤tInternalFormat, ¤tFormat, ¤tType); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 856 | |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 857 | bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) : |
| 858 | ValidES3ReadFormatType(context, currentInternalFormat, format, type); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 859 | |
| 860 | if (!(currentFormat == format && currentType == type) && !validReadFormat) |
| 861 | { |
| 862 | return gl::error(GL_INVALID_OPERATION, false); |
| 863 | } |
| 864 | |
| 865 | GLenum sizedInternalFormat = IsSizedInternalFormat(format, clientVersion) ? format : |
| 866 | GetSizedInternalFormat(format, type, clientVersion); |
| 867 | |
| 868 | GLsizei outputPitch = GetRowPitch(sizedInternalFormat, type, clientVersion, width, context->getPackAlignment()); |
| 869 | // sized query sanity check |
| 870 | if (bufSize) |
| 871 | { |
| 872 | int requiredSize = outputPitch * height; |
| 873 | if (requiredSize > *bufSize) |
| 874 | { |
| 875 | return gl::error(GL_INVALID_OPERATION, false); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | return true; |
| 880 | } |
| 881 | |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 882 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 883 | { |
| 884 | if (!ValidQueryType(context, target)) |
| 885 | { |
| 886 | return gl::error(GL_INVALID_ENUM, false); |
| 887 | } |
| 888 | |
| 889 | if (id == 0) |
| 890 | { |
| 891 | return gl::error(GL_INVALID_OPERATION, false); |
| 892 | } |
| 893 | |
| 894 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 895 | // of zero, if the active query object name for <target> is non-zero (for the |
| 896 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 897 | // the active query for either target is non-zero), if <id> is the name of an |
| 898 | // existing query object whose type does not match <target>, or if <id> is the |
| 899 | // active query object name for any query type, the error INVALID_OPERATION is |
| 900 | // generated. |
| 901 | |
| 902 | // Ensure no other queries are active |
| 903 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 904 | // separately that: |
| 905 | // a) The query ID passed is not the current active query for any target/type |
| 906 | // b) There are no active queries for the requested target (and in the case |
| 907 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 908 | // no query may be active for either if glBeginQuery targets either. |
| 909 | if (context->isQueryActive()) |
| 910 | { |
| 911 | return gl::error(GL_INVALID_OPERATION, false); |
| 912 | } |
| 913 | |
| 914 | Query *queryObject = context->getQuery(id, true, target); |
| 915 | |
| 916 | // check that name was obtained with glGenQueries |
| 917 | if (!queryObject) |
| 918 | { |
| 919 | return gl::error(GL_INVALID_OPERATION, false); |
| 920 | } |
| 921 | |
| 922 | // check for type mismatch |
| 923 | if (queryObject->getType() != target) |
| 924 | { |
| 925 | return gl::error(GL_INVALID_OPERATION, false); |
| 926 | } |
| 927 | |
| 928 | return true; |
| 929 | } |
| 930 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 931 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 932 | { |
| 933 | if (!ValidQueryType(context, target)) |
| 934 | { |
| 935 | return gl::error(GL_INVALID_ENUM, false); |
| 936 | } |
| 937 | |
| 938 | const Query *queryObject = context->getActiveQuery(target); |
| 939 | |
| 940 | if (queryObject == NULL) |
| 941 | { |
| 942 | return gl::error(GL_INVALID_OPERATION, false); |
| 943 | } |
| 944 | |
| 945 | if (!queryObject->isStarted()) |
| 946 | { |
| 947 | return gl::error(GL_INVALID_OPERATION, false); |
| 948 | } |
| 949 | |
| 950 | return true; |
| 951 | } |
| 952 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 953 | static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType, |
| 954 | GLint location, GLsizei count, LinkedUniform **uniformOut) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 955 | { |
| 956 | if (count < 0) |
| 957 | { |
| 958 | return gl::error(GL_INVALID_VALUE, false); |
| 959 | } |
| 960 | |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 961 | gl::ProgramBinary *programBinary = context->getCurrentProgramBinary(); |
| 962 | if (!programBinary) |
| 963 | { |
| 964 | return gl::error(GL_INVALID_OPERATION, false); |
| 965 | } |
| 966 | |
| 967 | if (location == -1) |
| 968 | { |
| 969 | // Silently ignore the uniform command |
| 970 | return false; |
| 971 | } |
| 972 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 973 | if (!programBinary->isValidUniformLocation(location)) |
| 974 | { |
| 975 | return gl::error(GL_INVALID_OPERATION, false); |
| 976 | } |
| 977 | |
| 978 | LinkedUniform *uniform = programBinary->getUniformByLocation(location); |
| 979 | |
| 980 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
| 981 | if (uniform->elementCount() == 1 && count > 1) |
| 982 | { |
| 983 | return gl::error(GL_INVALID_OPERATION, false); |
| 984 | } |
| 985 | |
| 986 | *uniformOut = uniform; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 987 | return true; |
| 988 | } |
| 989 | |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 990 | bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count) |
| 991 | { |
| 992 | // Check for ES3 uniform entry points |
| 993 | if (UniformComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3) |
| 994 | { |
| 995 | return gl::error(GL_INVALID_OPERATION, false); |
| 996 | } |
| 997 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 998 | LinkedUniform *uniform = NULL; |
| 999 | if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform)) |
| 1000 | { |
| 1001 | return false; |
| 1002 | } |
| 1003 | |
| 1004 | GLenum targetBoolType = UniformBoolVectorType(uniformType); |
| 1005 | bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT); |
| 1006 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 1007 | { |
| 1008 | return gl::error(GL_INVALID_OPERATION, false); |
| 1009 | } |
| 1010 | |
| 1011 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count, |
| 1015 | GLboolean transpose) |
| 1016 | { |
| 1017 | // Check for ES3 uniform entry points |
| 1018 | int rows = VariableRowCount(matrixType); |
| 1019 | int cols = VariableColumnCount(matrixType); |
| 1020 | if (rows != cols && context->getClientVersion() < 3) |
| 1021 | { |
| 1022 | return gl::error(GL_INVALID_OPERATION, false); |
| 1023 | } |
| 1024 | |
| 1025 | if (transpose != GL_FALSE && context->getClientVersion() < 3) |
| 1026 | { |
| 1027 | return gl::error(GL_INVALID_VALUE, false); |
| 1028 | } |
| 1029 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1030 | LinkedUniform *uniform = NULL; |
| 1031 | if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform)) |
| 1032 | { |
| 1033 | return false; |
| 1034 | } |
| 1035 | |
| 1036 | if (uniform->type != matrixType) |
| 1037 | { |
| 1038 | return gl::error(GL_INVALID_OPERATION, false); |
| 1039 | } |
| 1040 | |
| 1041 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1042 | } |
| 1043 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1044 | bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
| 1045 | { |
| 1046 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 1047 | { |
| 1048 | return gl::error(GL_INVALID_ENUM, false); |
| 1049 | } |
| 1050 | |
| 1051 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 1052 | { |
| 1053 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 1054 | |
| 1055 | if (colorAttachment >= context->getMaximumRenderTargets()) |
| 1056 | { |
| 1057 | return gl::error(GL_INVALID_OPERATION, false); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | switch (pname) |
| 1062 | { |
| 1063 | case GL_TEXTURE_BINDING_2D: |
| 1064 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1065 | case GL_TEXTURE_BINDING_3D: |
| 1066 | case GL_TEXTURE_BINDING_2D_ARRAY: |
| 1067 | if (context->getActiveSampler() >= context->getMaximumCombinedTextureImageUnits()) |
| 1068 | { |
| 1069 | return gl::error(GL_INVALID_OPERATION, false); |
| 1070 | } |
| 1071 | break; |
| 1072 | |
| 1073 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1074 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1075 | { |
| 1076 | Framebuffer *framebuffer = context->getReadFramebuffer(); |
| 1077 | ASSERT(framebuffer); |
| 1078 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1079 | { |
| 1080 | return gl::error(GL_INVALID_OPERATION, false); |
| 1081 | } |
| 1082 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 1083 | FramebufferAttachment *attachment = framebuffer->getReadColorbuffer(); |
| 1084 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1085 | { |
| 1086 | return gl::error(GL_INVALID_OPERATION, false); |
| 1087 | } |
| 1088 | } |
| 1089 | break; |
| 1090 | |
| 1091 | default: |
| 1092 | break; |
| 1093 | } |
| 1094 | |
| 1095 | // pname is valid, but there are no parameters to return |
| 1096 | if (numParams == 0) |
| 1097 | { |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | return true; |
| 1102 | } |
| 1103 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1104 | bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage, |
| 1105 | GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, |
| 1106 | GLint border, GLenum *textureFormatOut) |
| 1107 | { |
| 1108 | |
| 1109 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1110 | { |
| 1111 | return gl::error(GL_INVALID_ENUM, false); |
| 1112 | } |
| 1113 | |
| 1114 | if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0) |
| 1115 | { |
| 1116 | return gl::error(GL_INVALID_VALUE, false); |
| 1117 | } |
| 1118 | |
| 1119 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1120 | { |
| 1121 | return gl::error(GL_INVALID_VALUE, false); |
| 1122 | } |
| 1123 | |
| 1124 | if (border != 0) |
| 1125 | { |
| 1126 | return gl::error(GL_INVALID_VALUE, false); |
| 1127 | } |
| 1128 | |
| 1129 | if (!ValidMipLevel(context, target, level)) |
| 1130 | { |
| 1131 | return gl::error(GL_INVALID_VALUE, false); |
| 1132 | } |
| 1133 | |
| 1134 | gl::Framebuffer *framebuffer = context->getReadFramebuffer(); |
| 1135 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1136 | { |
| 1137 | return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
| 1138 | } |
| 1139 | |
| 1140 | if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0) |
| 1141 | { |
| 1142 | return gl::error(GL_INVALID_OPERATION, false); |
| 1143 | } |
| 1144 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1145 | gl::Texture *texture = NULL; |
| 1146 | GLenum textureInternalFormat = GL_NONE; |
| 1147 | bool textureCompressed = false; |
| 1148 | bool textureIsDepth = false; |
| 1149 | GLint textureLevelWidth = 0; |
| 1150 | GLint textureLevelHeight = 0; |
| 1151 | GLint textureLevelDepth = 0; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1152 | int maxDimension = 0; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1153 | |
| 1154 | switch (target) |
| 1155 | { |
| 1156 | case GL_TEXTURE_2D: |
| 1157 | { |
| 1158 | gl::Texture2D *texture2d = context->getTexture2D(); |
| 1159 | if (texture2d) |
| 1160 | { |
| 1161 | textureInternalFormat = texture2d->getInternalFormat(level); |
| 1162 | textureCompressed = texture2d->isCompressed(level); |
| 1163 | textureIsDepth = texture2d->isDepth(level); |
| 1164 | textureLevelWidth = texture2d->getWidth(level); |
| 1165 | textureLevelHeight = texture2d->getHeight(level); |
| 1166 | textureLevelDepth = 1; |
| 1167 | texture = texture2d; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1168 | maxDimension = context->getMaximum2DTextureDimension(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1169 | } |
| 1170 | } |
| 1171 | break; |
| 1172 | |
| 1173 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1174 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1175 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1176 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1177 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1178 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1179 | { |
| 1180 | gl::TextureCubeMap *textureCube = context->getTextureCubeMap(); |
| 1181 | if (textureCube) |
| 1182 | { |
| 1183 | textureInternalFormat = textureCube->getInternalFormat(target, level); |
| 1184 | textureCompressed = textureCube->isCompressed(target, level); |
| 1185 | textureIsDepth = false; |
| 1186 | textureLevelWidth = textureCube->getWidth(target, level); |
| 1187 | textureLevelHeight = textureCube->getHeight(target, level); |
| 1188 | textureLevelDepth = 1; |
| 1189 | texture = textureCube; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1190 | maxDimension = context->getMaximumCubeTextureDimension(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | break; |
| 1194 | |
| 1195 | case GL_TEXTURE_2D_ARRAY: |
| 1196 | { |
| 1197 | gl::Texture2DArray *texture2dArray = context->getTexture2DArray(); |
| 1198 | if (texture2dArray) |
| 1199 | { |
| 1200 | textureInternalFormat = texture2dArray->getInternalFormat(level); |
| 1201 | textureCompressed = texture2dArray->isCompressed(level); |
| 1202 | textureIsDepth = texture2dArray->isDepth(level); |
| 1203 | textureLevelWidth = texture2dArray->getWidth(level); |
| 1204 | textureLevelHeight = texture2dArray->getHeight(level); |
| 1205 | textureLevelDepth = texture2dArray->getLayers(level); |
| 1206 | texture = texture2dArray; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1207 | maxDimension = context->getMaximum2DTextureDimension(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | break; |
| 1211 | |
| 1212 | case GL_TEXTURE_3D: |
| 1213 | { |
| 1214 | gl::Texture3D *texture3d = context->getTexture3D(); |
| 1215 | if (texture3d) |
| 1216 | { |
| 1217 | textureInternalFormat = texture3d->getInternalFormat(level); |
| 1218 | textureCompressed = texture3d->isCompressed(level); |
| 1219 | textureIsDepth = texture3d->isDepth(level); |
| 1220 | textureLevelWidth = texture3d->getWidth(level); |
| 1221 | textureLevelHeight = texture3d->getHeight(level); |
| 1222 | textureLevelDepth = texture3d->getDepth(level); |
| 1223 | texture = texture3d; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1224 | maxDimension = context->getMaximum3DTextureDimension(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | break; |
| 1228 | |
| 1229 | default: |
| 1230 | return gl::error(GL_INVALID_ENUM, false); |
| 1231 | } |
| 1232 | |
| 1233 | if (!texture) |
| 1234 | { |
| 1235 | return gl::error(GL_INVALID_OPERATION, false); |
| 1236 | } |
| 1237 | |
| 1238 | if (texture->isImmutable() && !isSubImage) |
| 1239 | { |
| 1240 | return gl::error(GL_INVALID_OPERATION, false); |
| 1241 | } |
| 1242 | |
| 1243 | if (textureIsDepth) |
| 1244 | { |
| 1245 | return gl::error(GL_INVALID_OPERATION, false); |
| 1246 | } |
| 1247 | |
| 1248 | if (textureCompressed) |
| 1249 | { |
| 1250 | int clientVersion = context->getClientVersion(); |
| 1251 | GLint blockWidth = GetCompressedBlockWidth(textureInternalFormat, clientVersion); |
| 1252 | GLint blockHeight = GetCompressedBlockHeight(textureInternalFormat, clientVersion); |
| 1253 | |
| 1254 | if (((width % blockWidth) != 0 && width != textureLevelWidth) || |
| 1255 | ((height % blockHeight) != 0 && height != textureLevelHeight)) |
| 1256 | { |
| 1257 | return gl::error(GL_INVALID_OPERATION, false); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | if (isSubImage) |
| 1262 | { |
| 1263 | if (xoffset + width > textureLevelWidth || |
| 1264 | yoffset + height > textureLevelHeight || |
| 1265 | zoffset >= textureLevelDepth) |
| 1266 | { |
| 1267 | return gl::error(GL_INVALID_VALUE, false); |
| 1268 | } |
| 1269 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1270 | else |
| 1271 | { |
| 1272 | if (IsCubemapTextureTarget(target) && width != height) |
| 1273 | { |
| 1274 | return gl::error(GL_INVALID_VALUE, false); |
| 1275 | } |
| 1276 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 1277 | if (!IsValidInternalFormat(internalformat, context->getCaps().extensions, context->getClientVersion())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1278 | { |
| 1279 | return gl::error(GL_INVALID_ENUM, false); |
| 1280 | } |
| 1281 | |
| 1282 | int maxLevelDimension = (maxDimension >> level); |
| 1283 | if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension) |
| 1284 | { |
| 1285 | return gl::error(GL_INVALID_VALUE, false); |
| 1286 | } |
| 1287 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1288 | |
| 1289 | *textureFormatOut = textureInternalFormat; |
| 1290 | return true; |
| 1291 | } |
| 1292 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1293 | static bool ValidateDrawBase(const gl::Context *context, GLenum mode, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1294 | { |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1295 | switch (mode) |
| 1296 | { |
| 1297 | case GL_POINTS: |
| 1298 | case GL_LINES: |
| 1299 | case GL_LINE_LOOP: |
| 1300 | case GL_LINE_STRIP: |
| 1301 | case GL_TRIANGLES: |
| 1302 | case GL_TRIANGLE_STRIP: |
| 1303 | case GL_TRIANGLE_FAN: |
| 1304 | break; |
| 1305 | default: |
| 1306 | return gl::error(GL_INVALID_ENUM, false); |
| 1307 | } |
| 1308 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1309 | if (count < 0) |
| 1310 | { |
| 1311 | return gl::error(GL_INVALID_VALUE, false); |
| 1312 | } |
| 1313 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1314 | // Check for mapped buffers |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1315 | if (context->hasMappedBuffer(GL_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1316 | { |
| 1317 | return gl::error(GL_INVALID_OPERATION, false); |
| 1318 | } |
| 1319 | |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1320 | const gl::DepthStencilState &depthStencilState = context->getDepthStencilState(); |
| 1321 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 1322 | context->getStencilRef() != context->getStencilBackRef() || |
| 1323 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 1324 | { |
| 1325 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. |
| 1326 | // See Section 6.10 of the WebGL 1.0 spec |
| 1327 | ERR("This ANGLE implementation does not support separate front/back stencil " |
| 1328 | "writemasks, reference values, or stencil mask values."); |
| 1329 | return gl::error(GL_INVALID_OPERATION, false); |
| 1330 | } |
| 1331 | |
Jamie Madill | 9efa581 | 2014-06-20 13:21:24 -0400 | [diff] [blame] | 1332 | if (!context->getCurrentProgram()) |
| 1333 | { |
| 1334 | return gl::error(GL_INVALID_OPERATION, false); |
| 1335 | } |
| 1336 | |
| 1337 | gl::ProgramBinary *programBinary = context->getCurrentProgramBinary(); |
| 1338 | if (!programBinary->validateSamplers(NULL)) |
| 1339 | { |
| 1340 | return gl::error(GL_INVALID_OPERATION, false); |
| 1341 | } |
| 1342 | |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1343 | const gl::Framebuffer *fbo = context->getDrawFramebuffer(); |
| 1344 | if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1345 | { |
| 1346 | return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
| 1347 | } |
| 1348 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1349 | // No-op if zero count |
| 1350 | return (count > 0); |
| 1351 | } |
| 1352 | |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1353 | bool ValidateDrawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1354 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1355 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1356 | { |
| 1357 | return gl::error(GL_INVALID_VALUE, false); |
| 1358 | } |
| 1359 | |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1360 | gl::TransformFeedback *curTransformFeedback = context->getCurrentTransformFeedback(); |
| 1361 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() && |
| 1362 | curTransformFeedback->getDrawMode() != mode) |
| 1363 | { |
| 1364 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 1365 | // that does not match the current transform feedback object's draw mode (if transform feedback |
| 1366 | // is active), (3.0.2, section 2.14, pg 86) |
| 1367 | return gl::error(GL_INVALID_OPERATION, false); |
| 1368 | } |
| 1369 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1370 | if (!ValidateDrawBase(context, mode, count)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1371 | { |
| 1372 | return false; |
| 1373 | } |
| 1374 | |
| 1375 | return true; |
| 1376 | } |
| 1377 | |
| 1378 | bool ValidateDrawArraysInstanced(const gl::Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
| 1379 | { |
| 1380 | if (primcount < 0) |
| 1381 | { |
| 1382 | return gl::error(GL_INVALID_VALUE, false); |
| 1383 | } |
| 1384 | |
| 1385 | if (!ValidateDrawArrays(context, mode, first, count)) |
| 1386 | { |
| 1387 | return false; |
| 1388 | } |
| 1389 | |
| 1390 | // No-op if zero primitive count |
| 1391 | return (primcount > 0); |
| 1392 | } |
| 1393 | |
| 1394 | bool ValidateDrawElements(const gl::Context *context, GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) |
| 1395 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1396 | switch (type) |
| 1397 | { |
| 1398 | case GL_UNSIGNED_BYTE: |
| 1399 | case GL_UNSIGNED_SHORT: |
| 1400 | break; |
| 1401 | case GL_UNSIGNED_INT: |
| 1402 | if (!context->getCaps().extensions.elementIndexUint) |
| 1403 | { |
| 1404 | return gl::error(GL_INVALID_ENUM, false); |
| 1405 | } |
| 1406 | break; |
| 1407 | default: |
| 1408 | return gl::error(GL_INVALID_ENUM, false); |
| 1409 | } |
| 1410 | |
| 1411 | gl::TransformFeedback *curTransformFeedback = context->getCurrentTransformFeedback(); |
| 1412 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused()) |
| 1413 | { |
| 1414 | // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced |
| 1415 | // while transform feedback is active, (3.0.2, section 2.14, pg 86) |
| 1416 | return gl::error(GL_INVALID_OPERATION, false); |
| 1417 | } |
| 1418 | |
| 1419 | // Check for mapped buffers |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1420 | if (context->hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1421 | { |
| 1422 | return gl::error(GL_INVALID_OPERATION, false); |
| 1423 | } |
| 1424 | |
Jamie Madill | 9efa581 | 2014-06-20 13:21:24 -0400 | [diff] [blame] | 1425 | gl::VertexArray *vao = context->getCurrentVertexArray(); |
| 1426 | if (!indices && !vao->getElementArrayBuffer()) |
| 1427 | { |
| 1428 | return gl::error(GL_INVALID_OPERATION, false); |
| 1429 | } |
| 1430 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1431 | if (!ValidateDrawBase(context, mode, count)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1432 | { |
| 1433 | return false; |
| 1434 | } |
| 1435 | |
| 1436 | return true; |
| 1437 | } |
| 1438 | |
| 1439 | bool ValidateDrawElementsInstanced(const gl::Context *context, GLenum mode, GLsizei count, GLenum type, |
| 1440 | const GLvoid *indices, GLsizei primcount) |
| 1441 | { |
| 1442 | if (primcount < 0) |
| 1443 | { |
| 1444 | return gl::error(GL_INVALID_VALUE, false); |
| 1445 | } |
| 1446 | |
| 1447 | if (!ValidateDrawElements(context, mode, count, type, indices)) |
| 1448 | { |
| 1449 | return false; |
| 1450 | } |
| 1451 | |
| 1452 | // No-op zero primitive count |
| 1453 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1454 | } |
| 1455 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1456 | } |