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