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