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