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