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" |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 16 | #include "libGLESv2/FramebufferAttachment.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 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 | |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 170 | bool ValidImageSize(const gl::Context *context, GLenum target, GLint level, |
| 171 | GLsizei width, GLsizei height, GLsizei depth) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 172 | { |
| 173 | if (level < 0 || width < 0 || height < 0 || depth < 0) |
| 174 | { |
| 175 | return false; |
| 176 | } |
| 177 | |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 178 | if (!context->getCaps().extensions.textureNPOT && |
| 179 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 180 | { |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | if (!ValidMipLevel(context, target, level)) |
| 185 | { |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | return true; |
| 190 | } |
| 191 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 192 | bool ValidCompressedImageSize(const gl::Context *context, GLenum internalFormat, GLsizei width, GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 193 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 194 | if (!IsFormatCompressed(internalFormat)) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 195 | { |
| 196 | return false; |
| 197 | } |
| 198 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 199 | GLint blockWidth = GetCompressedBlockWidth(internalFormat); |
| 200 | GLint blockHeight = GetCompressedBlockHeight(internalFormat); |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 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. |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 276 | if (!gl::IsSizedInternalFormat(internalformat)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 277 | { |
| 278 | return gl::error(GL_INVALID_ENUM, false); |
| 279 | } |
| 280 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 281 | GLenum componentType = gl::GetComponentType(internalformat); |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 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 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 473 | if (mask & GL_COLOR_BUFFER_BIT) |
| 474 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 475 | gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 476 | gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 477 | |
| 478 | if (readColorBuffer && drawColorBuffer) |
| 479 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 480 | GLenum readInternalFormat = readColorBuffer->getActualFormat(); |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 481 | GLenum readComponentType = gl::GetComponentType(readInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 482 | |
| 483 | for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++) |
| 484 | { |
| 485 | if (drawFramebuffer->isEnabledColorAttachment(i)) |
| 486 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 487 | GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat(); |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 488 | GLenum drawComponentType = gl::GetComponentType(drawInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 489 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 490 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 491 | // 1) If the read buffer is fixed point format, the draw buffer must be as well |
| 492 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well |
| 493 | // 3) If the read buffer is a signed integer format, the draw buffer must be as well |
| 494 | if ( (readComponentType == GL_UNSIGNED_NORMALIZED || readComponentType == GL_SIGNED_NORMALIZED) && |
| 495 | !(drawComponentType == GL_UNSIGNED_NORMALIZED || drawComponentType == GL_SIGNED_NORMALIZED)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 496 | { |
| 497 | return gl::error(GL_INVALID_OPERATION, false); |
| 498 | } |
| 499 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 500 | if (readComponentType == GL_UNSIGNED_INT && drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 501 | { |
| 502 | return gl::error(GL_INVALID_OPERATION, false); |
| 503 | } |
| 504 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 505 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 506 | { |
| 507 | return gl::error(GL_INVALID_OPERATION, false); |
| 508 | } |
| 509 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 510 | if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 511 | { |
| 512 | return gl::error(GL_INVALID_OPERATION, false); |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 517 | if ((readComponentType == GL_INT || readComponentType == GL_UNSIGNED_INT) && filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 518 | { |
| 519 | return gl::error(GL_INVALID_OPERATION, false); |
| 520 | } |
| 521 | |
| 522 | if (fromAngleExtension) |
| 523 | { |
| 524 | const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType(); |
| 525 | if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER) |
| 526 | { |
| 527 | return gl::error(GL_INVALID_OPERATION, false); |
| 528 | } |
| 529 | |
| 530 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 531 | { |
| 532 | if (drawFramebuffer->isEnabledColorAttachment(colorAttachment)) |
| 533 | { |
| 534 | if (drawFramebuffer->getColorbufferType(colorAttachment) != GL_TEXTURE_2D && |
| 535 | drawFramebuffer->getColorbufferType(colorAttachment) != GL_RENDERBUFFER) |
| 536 | { |
| 537 | return gl::error(GL_INVALID_OPERATION, false); |
| 538 | } |
| 539 | |
| 540 | if (drawFramebuffer->getColorbuffer(colorAttachment)->getActualFormat() != readColorBuffer->getActualFormat()) |
| 541 | { |
| 542 | return gl::error(GL_INVALID_OPERATION, false); |
| 543 | } |
| 544 | } |
| 545 | } |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 546 | if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer, |
| 547 | srcX0, srcY0, srcX1, srcY1, |
| 548 | dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 549 | { |
| 550 | return gl::error(GL_INVALID_OPERATION, false); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 557 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 558 | gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer(); |
| 559 | gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 560 | |
| 561 | if (readDepthBuffer && drawDepthBuffer) |
| 562 | { |
| 563 | if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat()) |
| 564 | { |
| 565 | return gl::error(GL_INVALID_OPERATION, false); |
| 566 | } |
| 567 | |
| 568 | if (readDepthBuffer->getSamples() > 0 && !sameBounds) |
| 569 | { |
| 570 | return gl::error(GL_INVALID_OPERATION, false); |
| 571 | } |
| 572 | |
| 573 | if (fromAngleExtension) |
| 574 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 575 | if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer, |
| 576 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 577 | { |
| 578 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
| 579 | return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted |
| 580 | } |
| 581 | |
| 582 | if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0) |
| 583 | { |
| 584 | return gl::error(GL_INVALID_OPERATION, false); |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 591 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 592 | gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer(); |
| 593 | gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 594 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 595 | if (readStencilBuffer && drawStencilBuffer) |
| 596 | { |
| 597 | if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat()) |
| 598 | { |
| 599 | return gl::error(GL_INVALID_OPERATION, false); |
| 600 | } |
| 601 | |
| 602 | if (readStencilBuffer->getSamples() > 0 && !sameBounds) |
| 603 | { |
| 604 | return gl::error(GL_INVALID_OPERATION, false); |
| 605 | } |
| 606 | |
| 607 | if (fromAngleExtension) |
| 608 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 609 | if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer, |
| 610 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 611 | { |
| 612 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
| 613 | return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted |
| 614 | } |
| 615 | |
| 616 | if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0) |
| 617 | { |
| 618 | return gl::error(GL_INVALID_OPERATION, false); |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | return true; |
| 625 | } |
| 626 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 627 | bool ValidateGetVertexAttribParameters(GLenum pname, int clientVersion) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 628 | { |
| 629 | switch (pname) |
| 630 | { |
| 631 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 632 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 633 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 634 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 635 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 636 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 637 | case GL_CURRENT_VERTEX_ATTRIB: |
| 638 | return true; |
| 639 | |
| 640 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 641 | // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses |
| 642 | // the same constant. |
| 643 | META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE); |
| 644 | return true; |
| 645 | |
| 646 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 647 | return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false)); |
| 648 | |
| 649 | default: |
| 650 | return gl::error(GL_INVALID_ENUM, false); |
| 651 | } |
| 652 | } |
| 653 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 654 | bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 655 | { |
| 656 | switch (pname) |
| 657 | { |
| 658 | case GL_TEXTURE_WRAP_R: |
| 659 | case GL_TEXTURE_SWIZZLE_R: |
| 660 | case GL_TEXTURE_SWIZZLE_G: |
| 661 | case GL_TEXTURE_SWIZZLE_B: |
| 662 | case GL_TEXTURE_SWIZZLE_A: |
| 663 | case GL_TEXTURE_BASE_LEVEL: |
| 664 | case GL_TEXTURE_MAX_LEVEL: |
| 665 | case GL_TEXTURE_COMPARE_MODE: |
| 666 | case GL_TEXTURE_COMPARE_FUNC: |
| 667 | case GL_TEXTURE_MIN_LOD: |
| 668 | case GL_TEXTURE_MAX_LOD: |
| 669 | if (context->getClientVersion() < 3) |
| 670 | { |
| 671 | return gl::error(GL_INVALID_ENUM, false); |
| 672 | } |
| 673 | break; |
| 674 | |
| 675 | default: break; |
| 676 | } |
| 677 | |
| 678 | switch (pname) |
| 679 | { |
| 680 | case GL_TEXTURE_WRAP_S: |
| 681 | case GL_TEXTURE_WRAP_T: |
| 682 | case GL_TEXTURE_WRAP_R: |
| 683 | switch (param) |
| 684 | { |
| 685 | case GL_REPEAT: |
| 686 | case GL_CLAMP_TO_EDGE: |
| 687 | case GL_MIRRORED_REPEAT: |
| 688 | return true; |
| 689 | default: |
| 690 | return gl::error(GL_INVALID_ENUM, false); |
| 691 | } |
| 692 | |
| 693 | case GL_TEXTURE_MIN_FILTER: |
| 694 | switch (param) |
| 695 | { |
| 696 | case GL_NEAREST: |
| 697 | case GL_LINEAR: |
| 698 | case GL_NEAREST_MIPMAP_NEAREST: |
| 699 | case GL_LINEAR_MIPMAP_NEAREST: |
| 700 | case GL_NEAREST_MIPMAP_LINEAR: |
| 701 | case GL_LINEAR_MIPMAP_LINEAR: |
| 702 | return true; |
| 703 | default: |
| 704 | return gl::error(GL_INVALID_ENUM, false); |
| 705 | } |
| 706 | break; |
| 707 | |
| 708 | case GL_TEXTURE_MAG_FILTER: |
| 709 | switch (param) |
| 710 | { |
| 711 | case GL_NEAREST: |
| 712 | case GL_LINEAR: |
| 713 | return true; |
| 714 | default: |
| 715 | return gl::error(GL_INVALID_ENUM, false); |
| 716 | } |
| 717 | break; |
| 718 | |
| 719 | case GL_TEXTURE_USAGE_ANGLE: |
| 720 | switch (param) |
| 721 | { |
| 722 | case GL_NONE: |
| 723 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 724 | return true; |
| 725 | default: |
| 726 | return gl::error(GL_INVALID_ENUM, false); |
| 727 | } |
| 728 | break; |
| 729 | |
| 730 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 731 | if (!context->getCaps().extensions.textureFilterAnisotropic) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 732 | { |
| 733 | return gl::error(GL_INVALID_ENUM, false); |
| 734 | } |
| 735 | |
| 736 | // we assume the parameter passed to this validation method is truncated, not rounded |
| 737 | if (param < 1) |
| 738 | { |
| 739 | return gl::error(GL_INVALID_VALUE, false); |
| 740 | } |
| 741 | return true; |
| 742 | |
| 743 | case GL_TEXTURE_MIN_LOD: |
| 744 | case GL_TEXTURE_MAX_LOD: |
| 745 | // any value is permissible |
| 746 | return true; |
| 747 | |
| 748 | case GL_TEXTURE_COMPARE_MODE: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 749 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 750 | switch (param) |
| 751 | { |
| 752 | case GL_NONE: |
| 753 | case GL_COMPARE_REF_TO_TEXTURE: |
| 754 | return true; |
| 755 | default: |
| 756 | return gl::error(GL_INVALID_ENUM, false); |
| 757 | } |
| 758 | break; |
| 759 | |
| 760 | case GL_TEXTURE_COMPARE_FUNC: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 761 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 762 | switch (param) |
| 763 | { |
| 764 | case GL_LEQUAL: |
| 765 | case GL_GEQUAL: |
| 766 | case GL_LESS: |
| 767 | case GL_GREATER: |
| 768 | case GL_EQUAL: |
| 769 | case GL_NOTEQUAL: |
| 770 | case GL_ALWAYS: |
| 771 | case GL_NEVER: |
| 772 | return true; |
| 773 | default: |
| 774 | return gl::error(GL_INVALID_ENUM, false); |
| 775 | } |
| 776 | break; |
| 777 | |
| 778 | case GL_TEXTURE_SWIZZLE_R: |
| 779 | case GL_TEXTURE_SWIZZLE_G: |
| 780 | case GL_TEXTURE_SWIZZLE_B: |
| 781 | case GL_TEXTURE_SWIZZLE_A: |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 782 | switch (param) |
| 783 | { |
| 784 | case GL_RED: |
| 785 | case GL_GREEN: |
| 786 | case GL_BLUE: |
| 787 | case GL_ALPHA: |
| 788 | case GL_ZERO: |
| 789 | case GL_ONE: |
| 790 | return true; |
| 791 | default: |
| 792 | return gl::error(GL_INVALID_ENUM, false); |
| 793 | } |
| 794 | break; |
| 795 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 796 | case GL_TEXTURE_BASE_LEVEL: |
| 797 | case GL_TEXTURE_MAX_LEVEL: |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 798 | if (param < 0) |
| 799 | { |
| 800 | return gl::error(GL_INVALID_VALUE, false); |
| 801 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 802 | return true; |
| 803 | |
| 804 | default: |
| 805 | return gl::error(GL_INVALID_ENUM, false); |
| 806 | } |
| 807 | } |
| 808 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 809 | bool ValidateSamplerObjectParameter(GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 810 | { |
| 811 | switch (pname) |
| 812 | { |
| 813 | case GL_TEXTURE_MIN_FILTER: |
| 814 | case GL_TEXTURE_MAG_FILTER: |
| 815 | case GL_TEXTURE_WRAP_S: |
| 816 | case GL_TEXTURE_WRAP_T: |
| 817 | case GL_TEXTURE_WRAP_R: |
| 818 | case GL_TEXTURE_MIN_LOD: |
| 819 | case GL_TEXTURE_MAX_LOD: |
| 820 | case GL_TEXTURE_COMPARE_MODE: |
| 821 | case GL_TEXTURE_COMPARE_FUNC: |
| 822 | return true; |
| 823 | |
| 824 | default: |
| 825 | return gl::error(GL_INVALID_ENUM, false); |
| 826 | } |
| 827 | } |
| 828 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 829 | bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height, |
| 830 | GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels) |
| 831 | { |
| 832 | gl::Framebuffer *framebuffer = context->getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 833 | ASSERT(framebuffer); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 834 | |
| 835 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 836 | { |
| 837 | return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
| 838 | } |
| 839 | |
| 840 | if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0) |
| 841 | { |
| 842 | return gl::error(GL_INVALID_OPERATION, false); |
| 843 | } |
| 844 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 845 | if (!framebuffer->getReadColorbuffer()) |
| 846 | { |
| 847 | return gl::error(GL_INVALID_OPERATION, false); |
| 848 | } |
| 849 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 850 | GLenum currentInternalFormat, currentFormat, currentType; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 851 | GLuint clientVersion = context->getClientVersion(); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 852 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 853 | context->getCurrentReadFormatType(¤tInternalFormat, ¤tFormat, ¤tType); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 854 | |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 855 | bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) : |
| 856 | ValidES3ReadFormatType(context, currentInternalFormat, format, type); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 857 | |
| 858 | if (!(currentFormat == format && currentType == type) && !validReadFormat) |
| 859 | { |
| 860 | return gl::error(GL_INVALID_OPERATION, false); |
| 861 | } |
| 862 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 863 | GLenum sizedInternalFormat = IsSizedInternalFormat(format) ? format |
| 864 | : GetSizedInternalFormat(format, type); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 865 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 866 | GLsizei outputPitch = GetRowPitch(sizedInternalFormat, type, width, context->getPackAlignment()); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 867 | // sized query sanity check |
| 868 | if (bufSize) |
| 869 | { |
| 870 | int requiredSize = outputPitch * height; |
| 871 | if (requiredSize > *bufSize) |
| 872 | { |
| 873 | return gl::error(GL_INVALID_OPERATION, false); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | return true; |
| 878 | } |
| 879 | |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 880 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 881 | { |
| 882 | if (!ValidQueryType(context, target)) |
| 883 | { |
| 884 | return gl::error(GL_INVALID_ENUM, false); |
| 885 | } |
| 886 | |
| 887 | if (id == 0) |
| 888 | { |
| 889 | return gl::error(GL_INVALID_OPERATION, false); |
| 890 | } |
| 891 | |
| 892 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 893 | // of zero, if the active query object name for <target> is non-zero (for the |
| 894 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 895 | // the active query for either target is non-zero), if <id> is the name of an |
| 896 | // existing query object whose type does not match <target>, or if <id> is the |
| 897 | // active query object name for any query type, the error INVALID_OPERATION is |
| 898 | // generated. |
| 899 | |
| 900 | // Ensure no other queries are active |
| 901 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 902 | // separately that: |
| 903 | // a) The query ID passed is not the current active query for any target/type |
| 904 | // b) There are no active queries for the requested target (and in the case |
| 905 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 906 | // no query may be active for either if glBeginQuery targets either. |
| 907 | if (context->isQueryActive()) |
| 908 | { |
| 909 | return gl::error(GL_INVALID_OPERATION, false); |
| 910 | } |
| 911 | |
| 912 | Query *queryObject = context->getQuery(id, true, target); |
| 913 | |
| 914 | // check that name was obtained with glGenQueries |
| 915 | if (!queryObject) |
| 916 | { |
| 917 | return gl::error(GL_INVALID_OPERATION, false); |
| 918 | } |
| 919 | |
| 920 | // check for type mismatch |
| 921 | if (queryObject->getType() != target) |
| 922 | { |
| 923 | return gl::error(GL_INVALID_OPERATION, false); |
| 924 | } |
| 925 | |
| 926 | return true; |
| 927 | } |
| 928 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 929 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 930 | { |
| 931 | if (!ValidQueryType(context, target)) |
| 932 | { |
| 933 | return gl::error(GL_INVALID_ENUM, false); |
| 934 | } |
| 935 | |
| 936 | const Query *queryObject = context->getActiveQuery(target); |
| 937 | |
| 938 | if (queryObject == NULL) |
| 939 | { |
| 940 | return gl::error(GL_INVALID_OPERATION, false); |
| 941 | } |
| 942 | |
| 943 | if (!queryObject->isStarted()) |
| 944 | { |
| 945 | return gl::error(GL_INVALID_OPERATION, false); |
| 946 | } |
| 947 | |
| 948 | return true; |
| 949 | } |
| 950 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 951 | static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType, |
| 952 | GLint location, GLsizei count, LinkedUniform **uniformOut) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 953 | { |
| 954 | if (count < 0) |
| 955 | { |
| 956 | return gl::error(GL_INVALID_VALUE, false); |
| 957 | } |
| 958 | |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 959 | gl::ProgramBinary *programBinary = context->getCurrentProgramBinary(); |
| 960 | if (!programBinary) |
| 961 | { |
| 962 | return gl::error(GL_INVALID_OPERATION, false); |
| 963 | } |
| 964 | |
| 965 | if (location == -1) |
| 966 | { |
| 967 | // Silently ignore the uniform command |
| 968 | return false; |
| 969 | } |
| 970 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 971 | if (!programBinary->isValidUniformLocation(location)) |
| 972 | { |
| 973 | return gl::error(GL_INVALID_OPERATION, false); |
| 974 | } |
| 975 | |
| 976 | LinkedUniform *uniform = programBinary->getUniformByLocation(location); |
| 977 | |
| 978 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
| 979 | if (uniform->elementCount() == 1 && count > 1) |
| 980 | { |
| 981 | return gl::error(GL_INVALID_OPERATION, false); |
| 982 | } |
| 983 | |
| 984 | *uniformOut = uniform; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 985 | return true; |
| 986 | } |
| 987 | |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 988 | bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count) |
| 989 | { |
| 990 | // Check for ES3 uniform entry points |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 991 | if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 992 | { |
| 993 | return gl::error(GL_INVALID_OPERATION, false); |
| 994 | } |
| 995 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 996 | LinkedUniform *uniform = NULL; |
| 997 | if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform)) |
| 998 | { |
| 999 | return false; |
| 1000 | } |
| 1001 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1002 | GLenum targetBoolType = VariableBoolVectorType(uniformType); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1003 | bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT); |
| 1004 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 1005 | { |
| 1006 | return gl::error(GL_INVALID_OPERATION, false); |
| 1007 | } |
| 1008 | |
| 1009 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count, |
| 1013 | GLboolean transpose) |
| 1014 | { |
| 1015 | // Check for ES3 uniform entry points |
| 1016 | int rows = VariableRowCount(matrixType); |
| 1017 | int cols = VariableColumnCount(matrixType); |
| 1018 | if (rows != cols && context->getClientVersion() < 3) |
| 1019 | { |
| 1020 | return gl::error(GL_INVALID_OPERATION, false); |
| 1021 | } |
| 1022 | |
| 1023 | if (transpose != GL_FALSE && context->getClientVersion() < 3) |
| 1024 | { |
| 1025 | return gl::error(GL_INVALID_VALUE, false); |
| 1026 | } |
| 1027 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1028 | LinkedUniform *uniform = NULL; |
| 1029 | if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform)) |
| 1030 | { |
| 1031 | return false; |
| 1032 | } |
| 1033 | |
| 1034 | if (uniform->type != matrixType) |
| 1035 | { |
| 1036 | return gl::error(GL_INVALID_OPERATION, false); |
| 1037 | } |
| 1038 | |
| 1039 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1042 | bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
| 1043 | { |
| 1044 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 1045 | { |
| 1046 | return gl::error(GL_INVALID_ENUM, false); |
| 1047 | } |
| 1048 | |
| 1049 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 1050 | { |
| 1051 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 1052 | |
| 1053 | if (colorAttachment >= context->getMaximumRenderTargets()) |
| 1054 | { |
| 1055 | return gl::error(GL_INVALID_OPERATION, false); |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | switch (pname) |
| 1060 | { |
| 1061 | case GL_TEXTURE_BINDING_2D: |
| 1062 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1063 | case GL_TEXTURE_BINDING_3D: |
| 1064 | case GL_TEXTURE_BINDING_2D_ARRAY: |
| 1065 | if (context->getActiveSampler() >= context->getMaximumCombinedTextureImageUnits()) |
| 1066 | { |
| 1067 | return gl::error(GL_INVALID_OPERATION, false); |
| 1068 | } |
| 1069 | break; |
| 1070 | |
| 1071 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1072 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1073 | { |
| 1074 | Framebuffer *framebuffer = context->getReadFramebuffer(); |
| 1075 | ASSERT(framebuffer); |
| 1076 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1077 | { |
| 1078 | return gl::error(GL_INVALID_OPERATION, false); |
| 1079 | } |
| 1080 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 1081 | FramebufferAttachment *attachment = framebuffer->getReadColorbuffer(); |
| 1082 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1083 | { |
| 1084 | return gl::error(GL_INVALID_OPERATION, false); |
| 1085 | } |
| 1086 | } |
| 1087 | break; |
| 1088 | |
| 1089 | default: |
| 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | // pname is valid, but there are no parameters to return |
| 1094 | if (numParams == 0) |
| 1095 | { |
| 1096 | return false; |
| 1097 | } |
| 1098 | |
| 1099 | return true; |
| 1100 | } |
| 1101 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1102 | bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage, |
| 1103 | GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, |
| 1104 | GLint border, GLenum *textureFormatOut) |
| 1105 | { |
| 1106 | |
| 1107 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1108 | { |
| 1109 | return gl::error(GL_INVALID_ENUM, false); |
| 1110 | } |
| 1111 | |
| 1112 | if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0) |
| 1113 | { |
| 1114 | return gl::error(GL_INVALID_VALUE, false); |
| 1115 | } |
| 1116 | |
| 1117 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1118 | { |
| 1119 | return gl::error(GL_INVALID_VALUE, false); |
| 1120 | } |
| 1121 | |
| 1122 | if (border != 0) |
| 1123 | { |
| 1124 | return gl::error(GL_INVALID_VALUE, false); |
| 1125 | } |
| 1126 | |
| 1127 | if (!ValidMipLevel(context, target, level)) |
| 1128 | { |
| 1129 | return gl::error(GL_INVALID_VALUE, false); |
| 1130 | } |
| 1131 | |
| 1132 | gl::Framebuffer *framebuffer = context->getReadFramebuffer(); |
| 1133 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1134 | { |
| 1135 | return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
| 1136 | } |
| 1137 | |
| 1138 | if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0) |
| 1139 | { |
| 1140 | return gl::error(GL_INVALID_OPERATION, false); |
| 1141 | } |
| 1142 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1143 | gl::Texture *texture = NULL; |
| 1144 | GLenum textureInternalFormat = GL_NONE; |
| 1145 | bool textureCompressed = false; |
| 1146 | bool textureIsDepth = false; |
| 1147 | GLint textureLevelWidth = 0; |
| 1148 | GLint textureLevelHeight = 0; |
| 1149 | GLint textureLevelDepth = 0; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1150 | int maxDimension = 0; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1151 | |
| 1152 | switch (target) |
| 1153 | { |
| 1154 | case GL_TEXTURE_2D: |
| 1155 | { |
| 1156 | gl::Texture2D *texture2d = context->getTexture2D(); |
| 1157 | if (texture2d) |
| 1158 | { |
| 1159 | textureInternalFormat = texture2d->getInternalFormat(level); |
| 1160 | textureCompressed = texture2d->isCompressed(level); |
| 1161 | textureIsDepth = texture2d->isDepth(level); |
| 1162 | textureLevelWidth = texture2d->getWidth(level); |
| 1163 | textureLevelHeight = texture2d->getHeight(level); |
| 1164 | textureLevelDepth = 1; |
| 1165 | texture = texture2d; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1166 | maxDimension = context->getMaximum2DTextureDimension(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | break; |
| 1170 | |
| 1171 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1172 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1173 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1174 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1175 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1176 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1177 | { |
| 1178 | gl::TextureCubeMap *textureCube = context->getTextureCubeMap(); |
| 1179 | if (textureCube) |
| 1180 | { |
| 1181 | textureInternalFormat = textureCube->getInternalFormat(target, level); |
| 1182 | textureCompressed = textureCube->isCompressed(target, level); |
| 1183 | textureIsDepth = false; |
| 1184 | textureLevelWidth = textureCube->getWidth(target, level); |
| 1185 | textureLevelHeight = textureCube->getHeight(target, level); |
| 1186 | textureLevelDepth = 1; |
| 1187 | texture = textureCube; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1188 | maxDimension = context->getMaximumCubeTextureDimension(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | break; |
| 1192 | |
| 1193 | case GL_TEXTURE_2D_ARRAY: |
| 1194 | { |
| 1195 | gl::Texture2DArray *texture2dArray = context->getTexture2DArray(); |
| 1196 | if (texture2dArray) |
| 1197 | { |
| 1198 | textureInternalFormat = texture2dArray->getInternalFormat(level); |
| 1199 | textureCompressed = texture2dArray->isCompressed(level); |
| 1200 | textureIsDepth = texture2dArray->isDepth(level); |
| 1201 | textureLevelWidth = texture2dArray->getWidth(level); |
| 1202 | textureLevelHeight = texture2dArray->getHeight(level); |
| 1203 | textureLevelDepth = texture2dArray->getLayers(level); |
| 1204 | texture = texture2dArray; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1205 | maxDimension = context->getMaximum2DTextureDimension(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | break; |
| 1209 | |
| 1210 | case GL_TEXTURE_3D: |
| 1211 | { |
| 1212 | gl::Texture3D *texture3d = context->getTexture3D(); |
| 1213 | if (texture3d) |
| 1214 | { |
| 1215 | textureInternalFormat = texture3d->getInternalFormat(level); |
| 1216 | textureCompressed = texture3d->isCompressed(level); |
| 1217 | textureIsDepth = texture3d->isDepth(level); |
| 1218 | textureLevelWidth = texture3d->getWidth(level); |
| 1219 | textureLevelHeight = texture3d->getHeight(level); |
| 1220 | textureLevelDepth = texture3d->getDepth(level); |
| 1221 | texture = texture3d; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1222 | maxDimension = context->getMaximum3DTextureDimension(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | break; |
| 1226 | |
| 1227 | default: |
| 1228 | return gl::error(GL_INVALID_ENUM, false); |
| 1229 | } |
| 1230 | |
| 1231 | if (!texture) |
| 1232 | { |
| 1233 | return gl::error(GL_INVALID_OPERATION, false); |
| 1234 | } |
| 1235 | |
| 1236 | if (texture->isImmutable() && !isSubImage) |
| 1237 | { |
| 1238 | return gl::error(GL_INVALID_OPERATION, false); |
| 1239 | } |
| 1240 | |
| 1241 | if (textureIsDepth) |
| 1242 | { |
| 1243 | return gl::error(GL_INVALID_OPERATION, false); |
| 1244 | } |
| 1245 | |
| 1246 | if (textureCompressed) |
| 1247 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 1248 | GLint blockWidth = GetCompressedBlockWidth(textureInternalFormat); |
| 1249 | GLint blockHeight = GetCompressedBlockHeight(textureInternalFormat); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1250 | |
| 1251 | if (((width % blockWidth) != 0 && width != textureLevelWidth) || |
| 1252 | ((height % blockHeight) != 0 && height != textureLevelHeight)) |
| 1253 | { |
| 1254 | return gl::error(GL_INVALID_OPERATION, false); |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | if (isSubImage) |
| 1259 | { |
| 1260 | if (xoffset + width > textureLevelWidth || |
| 1261 | yoffset + height > textureLevelHeight || |
| 1262 | zoffset >= textureLevelDepth) |
| 1263 | { |
| 1264 | return gl::error(GL_INVALID_VALUE, false); |
| 1265 | } |
| 1266 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1267 | else |
| 1268 | { |
| 1269 | if (IsCubemapTextureTarget(target) && width != height) |
| 1270 | { |
| 1271 | return gl::error(GL_INVALID_VALUE, false); |
| 1272 | } |
| 1273 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 1274 | if (!IsValidInternalFormat(internalformat, context->getCaps().extensions, context->getClientVersion())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1275 | { |
| 1276 | return gl::error(GL_INVALID_ENUM, false); |
| 1277 | } |
| 1278 | |
| 1279 | int maxLevelDimension = (maxDimension >> level); |
| 1280 | if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension) |
| 1281 | { |
| 1282 | return gl::error(GL_INVALID_VALUE, false); |
| 1283 | } |
| 1284 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1285 | |
| 1286 | *textureFormatOut = textureInternalFormat; |
| 1287 | return true; |
| 1288 | } |
| 1289 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1290 | static bool ValidateDrawBase(const gl::Context *context, GLenum mode, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1291 | { |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1292 | switch (mode) |
| 1293 | { |
| 1294 | case GL_POINTS: |
| 1295 | case GL_LINES: |
| 1296 | case GL_LINE_LOOP: |
| 1297 | case GL_LINE_STRIP: |
| 1298 | case GL_TRIANGLES: |
| 1299 | case GL_TRIANGLE_STRIP: |
| 1300 | case GL_TRIANGLE_FAN: |
| 1301 | break; |
| 1302 | default: |
| 1303 | return gl::error(GL_INVALID_ENUM, false); |
| 1304 | } |
| 1305 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1306 | if (count < 0) |
| 1307 | { |
| 1308 | return gl::error(GL_INVALID_VALUE, false); |
| 1309 | } |
| 1310 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1311 | // Check for mapped buffers |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1312 | if (context->hasMappedBuffer(GL_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1313 | { |
| 1314 | return gl::error(GL_INVALID_OPERATION, false); |
| 1315 | } |
| 1316 | |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1317 | const gl::DepthStencilState &depthStencilState = context->getDepthStencilState(); |
| 1318 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 1319 | context->getStencilRef() != context->getStencilBackRef() || |
| 1320 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 1321 | { |
| 1322 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. |
| 1323 | // See Section 6.10 of the WebGL 1.0 spec |
| 1324 | ERR("This ANGLE implementation does not support separate front/back stencil " |
| 1325 | "writemasks, reference values, or stencil mask values."); |
| 1326 | return gl::error(GL_INVALID_OPERATION, false); |
| 1327 | } |
| 1328 | |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1329 | const gl::Framebuffer *fbo = context->getDrawFramebuffer(); |
| 1330 | if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1331 | { |
| 1332 | return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false); |
| 1333 | } |
| 1334 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1335 | // No-op if zero count |
| 1336 | return (count > 0); |
| 1337 | } |
| 1338 | |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1339 | bool ValidateDrawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1340 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1341 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1342 | { |
| 1343 | return gl::error(GL_INVALID_VALUE, false); |
| 1344 | } |
| 1345 | |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1346 | gl::TransformFeedback *curTransformFeedback = context->getCurrentTransformFeedback(); |
| 1347 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() && |
| 1348 | curTransformFeedback->getDrawMode() != mode) |
| 1349 | { |
| 1350 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 1351 | // that does not match the current transform feedback object's draw mode (if transform feedback |
| 1352 | // is active), (3.0.2, section 2.14, pg 86) |
| 1353 | return gl::error(GL_INVALID_OPERATION, false); |
| 1354 | } |
| 1355 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1356 | if (!ValidateDrawBase(context, mode, count)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1357 | { |
| 1358 | return false; |
| 1359 | } |
| 1360 | |
| 1361 | return true; |
| 1362 | } |
| 1363 | |
| 1364 | bool ValidateDrawArraysInstanced(const gl::Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
| 1365 | { |
| 1366 | if (primcount < 0) |
| 1367 | { |
| 1368 | return gl::error(GL_INVALID_VALUE, false); |
| 1369 | } |
| 1370 | |
| 1371 | if (!ValidateDrawArrays(context, mode, first, count)) |
| 1372 | { |
| 1373 | return false; |
| 1374 | } |
| 1375 | |
| 1376 | // No-op if zero primitive count |
| 1377 | return (primcount > 0); |
| 1378 | } |
| 1379 | |
| 1380 | bool ValidateDrawElements(const gl::Context *context, GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) |
| 1381 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1382 | switch (type) |
| 1383 | { |
| 1384 | case GL_UNSIGNED_BYTE: |
| 1385 | case GL_UNSIGNED_SHORT: |
| 1386 | break; |
| 1387 | case GL_UNSIGNED_INT: |
| 1388 | if (!context->getCaps().extensions.elementIndexUint) |
| 1389 | { |
| 1390 | return gl::error(GL_INVALID_ENUM, false); |
| 1391 | } |
| 1392 | break; |
| 1393 | default: |
| 1394 | return gl::error(GL_INVALID_ENUM, false); |
| 1395 | } |
| 1396 | |
| 1397 | gl::TransformFeedback *curTransformFeedback = context->getCurrentTransformFeedback(); |
| 1398 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused()) |
| 1399 | { |
| 1400 | // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced |
| 1401 | // while transform feedback is active, (3.0.2, section 2.14, pg 86) |
| 1402 | return gl::error(GL_INVALID_OPERATION, false); |
| 1403 | } |
| 1404 | |
| 1405 | // Check for mapped buffers |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1406 | if (context->hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1407 | { |
| 1408 | return gl::error(GL_INVALID_OPERATION, false); |
| 1409 | } |
| 1410 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1411 | if (!ValidateDrawBase(context, mode, count)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1412 | { |
| 1413 | return false; |
| 1414 | } |
| 1415 | |
| 1416 | return true; |
| 1417 | } |
| 1418 | |
| 1419 | bool ValidateDrawElementsInstanced(const gl::Context *context, GLenum mode, GLsizei count, GLenum type, |
| 1420 | const GLvoid *indices, GLsizei primcount) |
| 1421 | { |
| 1422 | if (primcount < 0) |
| 1423 | { |
| 1424 | return gl::error(GL_INVALID_VALUE, false); |
| 1425 | } |
| 1426 | |
| 1427 | if (!ValidateDrawElements(context, mode, count, type, indices)) |
| 1428 | { |
| 1429 | return false; |
| 1430 | } |
| 1431 | |
| 1432 | // No-op zero primitive count |
| 1433 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame^] | 1436 | bool ValidateFramebufferTexture2D(const gl::Context *context, GLenum target, GLenum attachment, |
| 1437 | GLenum textarget, GLuint texture, GLint level) |
| 1438 | { |
| 1439 | if (context->getClientVersion() < 3 && |
| 1440 | !ValidateES2FramebufferTextureParameters(context, target, attachment, textarget, texture, level)) |
| 1441 | { |
| 1442 | return false; |
| 1443 | } |
| 1444 | |
| 1445 | if (context->getClientVersion() >= 3 && |
| 1446 | !ValidateES3FramebufferTextureParameters(context, target, attachment, textarget, texture, level, 0, false)) |
| 1447 | { |
| 1448 | return false; |
| 1449 | } |
| 1450 | |
| 1451 | return true; |
| 1452 | } |
| 1453 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1454 | } |