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