Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES.h: Validation functions for generic OpenGL ES entry point parameters |
| 8 | |
| 9 | #include "libGLESv2/validationES.h" |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 10 | #include "libGLESv2/validationES2.h" |
| 11 | #include "libGLESv2/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 12 | #include "libGLESv2/Context.h" |
| 13 | #include "libGLESv2/Texture.h" |
| 14 | #include "libGLESv2/Framebuffer.h" |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 15 | #include "libGLESv2/FramebufferAttachment.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 16 | #include "libGLESv2/formatutils.h" |
| 17 | #include "libGLESv2/main.h" |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 18 | #include "libGLESv2/Query.h" |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 19 | #include "libGLESv2/ProgramBinary.h" |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 20 | #include "libGLESv2/TransformFeedback.h" |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 21 | #include "libGLESv2/VertexArray.h" |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 22 | #include "libGLESv2/renderer/BufferImpl.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 | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1304 | static bool ValidateDrawBase(const gl::State &state, GLenum mode, GLsizei count, GLsizei maxVertex, GLsizei primcount) |
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 | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1326 | if (state.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 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1331 | const gl::DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1332 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1333 | state.getStencilRef() != state.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 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1343 | const gl::Framebuffer *fbo = state.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 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1349 | if (state.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 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1354 | gl::ProgramBinary *programBinary = state.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 | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1360 | // Buffer validations |
| 1361 | const VertexArray *vao = state.getVertexArray(); |
| 1362 | for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 1363 | { |
| 1364 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
| 1365 | bool attribActive = (programBinary->getSemanticIndex(attributeIndex) != -1); |
| 1366 | if (attribActive && attrib.enabled) |
| 1367 | { |
| 1368 | gl::Buffer *buffer = attrib.buffer.get(); |
| 1369 | |
| 1370 | if (buffer) |
| 1371 | { |
| 1372 | GLint64 attribStride = static_cast<GLint64>(ComputeVertexAttributeStride(attrib)); |
| 1373 | GLint64 maxVertexElement = 0; |
| 1374 | |
| 1375 | if (attrib.divisor > 0) |
| 1376 | { |
| 1377 | maxVertexElement = static_cast<GLint64>(primcount) / static_cast<GLint64>(attrib.divisor); |
| 1378 | } |
| 1379 | else |
| 1380 | { |
| 1381 | maxVertexElement = static_cast<GLint64>(maxVertex); |
| 1382 | } |
| 1383 | |
| 1384 | GLint64 attribDataSize = maxVertexElement * attribStride; |
| 1385 | |
| 1386 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 1387 | // We can return INVALID_OPERATION if our vertex attribute does not have |
| 1388 | // enough backing data. |
| 1389 | if (attribDataSize > buffer->getSize()) |
| 1390 | { |
| 1391 | return gl::error(GL_INVALID_OPERATION, false); |
| 1392 | } |
| 1393 | } |
| 1394 | else if (attrib.pointer == NULL) |
| 1395 | { |
| 1396 | // This is an application error that would normally result in a crash, |
| 1397 | // but we catch it and return an error |
| 1398 | ERR("An enabled vertex array has no buffer and no pointer."); |
| 1399 | return gl::error(GL_INVALID_OPERATION, false); |
| 1400 | } |
| 1401 | } |
| 1402 | } |
| 1403 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1404 | // No-op if zero count |
| 1405 | return (count > 0); |
| 1406 | } |
| 1407 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1408 | bool ValidateDrawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1409 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1410 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1411 | { |
| 1412 | return gl::error(GL_INVALID_VALUE, false); |
| 1413 | } |
| 1414 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1415 | const State &state = context->getState(); |
| 1416 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1417 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() && |
| 1418 | curTransformFeedback->getDrawMode() != mode) |
| 1419 | { |
| 1420 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 1421 | // that does not match the current transform feedback object's draw mode (if transform feedback |
| 1422 | // is active), (3.0.2, section 2.14, pg 86) |
| 1423 | return gl::error(GL_INVALID_OPERATION, false); |
| 1424 | } |
| 1425 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1426 | if (!ValidateDrawBase(state, mode, count, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1427 | { |
| 1428 | return false; |
| 1429 | } |
| 1430 | |
| 1431 | return true; |
| 1432 | } |
| 1433 | |
| 1434 | bool ValidateDrawArraysInstanced(const gl::Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
| 1435 | { |
| 1436 | if (primcount < 0) |
| 1437 | { |
| 1438 | return gl::error(GL_INVALID_VALUE, false); |
| 1439 | } |
| 1440 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1441 | if (!ValidateDrawArrays(context, mode, first, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1442 | { |
| 1443 | return false; |
| 1444 | } |
| 1445 | |
| 1446 | // No-op if zero primitive count |
| 1447 | return (primcount > 0); |
| 1448 | } |
| 1449 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1450 | bool ValidateDrawElements(const gl::Context *context, GLenum mode, GLsizei count, GLenum type, |
| 1451 | const GLvoid* indices, GLsizei primcount, rx::RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1452 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1453 | switch (type) |
| 1454 | { |
| 1455 | case GL_UNSIGNED_BYTE: |
| 1456 | case GL_UNSIGNED_SHORT: |
| 1457 | break; |
| 1458 | case GL_UNSIGNED_INT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1459 | if (!context->getExtensions().elementIndexUint) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1460 | { |
| 1461 | return gl::error(GL_INVALID_ENUM, false); |
| 1462 | } |
| 1463 | break; |
| 1464 | default: |
| 1465 | return gl::error(GL_INVALID_ENUM, false); |
| 1466 | } |
| 1467 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1468 | const State &state = context->getState(); |
| 1469 | |
| 1470 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1471 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused()) |
| 1472 | { |
| 1473 | // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced |
| 1474 | // while transform feedback is active, (3.0.2, section 2.14, pg 86) |
| 1475 | return gl::error(GL_INVALID_OPERATION, false); |
| 1476 | } |
| 1477 | |
| 1478 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1479 | if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1480 | { |
| 1481 | return gl::error(GL_INVALID_OPERATION, false); |
| 1482 | } |
| 1483 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1484 | const gl::VertexArray *vao = state.getVertexArray(); |
| 1485 | const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
| 1486 | if (!indices && !elementArrayBuffer) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1487 | { |
| 1488 | return gl::error(GL_INVALID_OPERATION, false); |
| 1489 | } |
| 1490 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1491 | if (elementArrayBuffer) |
| 1492 | { |
| 1493 | const gl::Type &typeInfo = gl::GetTypeInfo(type); |
| 1494 | |
| 1495 | GLint64 offset = reinterpret_cast<GLint64>(indices); |
| 1496 | GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset; |
| 1497 | |
| 1498 | // check for integer overflows |
| 1499 | if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) || |
| 1500 | byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max())) |
| 1501 | { |
| 1502 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 1503 | } |
| 1504 | |
| 1505 | // Check for reading past the end of the bound buffer object |
| 1506 | if (byteCount > elementArrayBuffer->getSize()) |
| 1507 | { |
| 1508 | return gl::error(GL_INVALID_OPERATION, false); |
| 1509 | } |
| 1510 | } |
| 1511 | else if (!indices) |
| 1512 | { |
| 1513 | // Catch this programming error here |
| 1514 | return gl::error(GL_INVALID_OPERATION, false); |
| 1515 | } |
| 1516 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1517 | // Use max index to validate if our vertex buffers are large enough for the pull. |
| 1518 | // TODO: offer fast path, with disabled index validation. |
| 1519 | // TODO: also disable index checking on back-ends that are robust to out-of-range accesses. |
| 1520 | if (elementArrayBuffer) |
| 1521 | { |
| 1522 | unsigned int offset = reinterpret_cast<unsigned int>(indices); |
| 1523 | if (!elementArrayBuffer->getIndexRangeCache()->findRange(type, offset, count, indexRangeOut, NULL)) |
| 1524 | { |
| 1525 | const void *dataPointer = elementArrayBuffer->getImplementation()->getData(); |
| 1526 | const uint8_t *offsetPointer = static_cast<const uint8_t *>(dataPointer) + offset; |
| 1527 | *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, offsetPointer, count); |
| 1528 | } |
| 1529 | } |
| 1530 | else |
| 1531 | { |
| 1532 | *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, indices, count); |
| 1533 | } |
| 1534 | |
| 1535 | if (!ValidateDrawBase(state, mode, count, static_cast<GLsizei>(indexRangeOut->end), primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1536 | { |
| 1537 | return false; |
| 1538 | } |
| 1539 | |
| 1540 | return true; |
| 1541 | } |
| 1542 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1543 | bool ValidateDrawElementsInstanced(const gl::Context *context, |
| 1544 | GLenum mode, GLsizei count, GLenum type, |
| 1545 | const GLvoid *indices, GLsizei primcount, |
| 1546 | rx::RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1547 | { |
| 1548 | if (primcount < 0) |
| 1549 | { |
| 1550 | return gl::error(GL_INVALID_VALUE, false); |
| 1551 | } |
| 1552 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1553 | if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1554 | { |
| 1555 | return false; |
| 1556 | } |
| 1557 | |
| 1558 | // No-op zero primitive count |
| 1559 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1560 | } |
| 1561 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1562 | bool ValidateFramebufferTextureBase(const gl::Context *context, GLenum target, GLenum attachment, |
| 1563 | GLuint texture, GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1564 | { |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1565 | if (!ValidFramebufferTarget(target)) |
| 1566 | { |
| 1567 | return gl::error(GL_INVALID_ENUM, false); |
| 1568 | } |
| 1569 | |
| 1570 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1571 | { |
| 1572 | return false; |
| 1573 | } |
| 1574 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1575 | if (texture != 0) |
| 1576 | { |
| 1577 | gl::Texture *tex = context->getTexture(texture); |
| 1578 | |
| 1579 | if (tex == NULL) |
| 1580 | { |
| 1581 | return gl::error(GL_INVALID_OPERATION, false); |
| 1582 | } |
| 1583 | |
| 1584 | if (level < 0) |
| 1585 | { |
| 1586 | return gl::error(GL_INVALID_VALUE, false); |
| 1587 | } |
| 1588 | } |
| 1589 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1590 | const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
| 1591 | GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id(); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1592 | |
| 1593 | if (framebufferHandle == 0 || !framebuffer) |
| 1594 | { |
| 1595 | return gl::error(GL_INVALID_OPERATION, false); |
| 1596 | } |
| 1597 | |
| 1598 | return true; |
| 1599 | } |
| 1600 | |
| 1601 | bool ValidateFramebufferTexture2D(const gl::Context *context, GLenum target, GLenum attachment, |
| 1602 | GLenum textarget, GLuint texture, GLint level) |
| 1603 | { |
| 1604 | // Attachments are required to be bound to level 0 in ES2 |
| 1605 | if (context->getClientVersion() < 3 && level != 0) |
| 1606 | { |
| 1607 | return gl::error(GL_INVALID_VALUE, false); |
| 1608 | } |
| 1609 | |
| 1610 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1611 | { |
| 1612 | return false; |
| 1613 | } |
| 1614 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1615 | if (texture != 0) |
| 1616 | { |
| 1617 | gl::Texture *tex = context->getTexture(texture); |
| 1618 | ASSERT(tex); |
| 1619 | |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1620 | const gl::Caps &caps = context->getCaps(); |
| 1621 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1622 | switch (textarget) |
| 1623 | { |
| 1624 | case GL_TEXTURE_2D: |
| 1625 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1626 | if (level > gl::log2(caps.max2DTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1627 | { |
| 1628 | return gl::error(GL_INVALID_VALUE, false); |
| 1629 | } |
| 1630 | if (tex->getTarget() != GL_TEXTURE_2D) |
| 1631 | { |
| 1632 | return gl::error(GL_INVALID_OPERATION, false); |
| 1633 | } |
| 1634 | gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex); |
| 1635 | if (tex2d->isCompressed(level)) |
| 1636 | { |
| 1637 | return gl::error(GL_INVALID_OPERATION, false); |
| 1638 | } |
| 1639 | } |
| 1640 | break; |
| 1641 | |
| 1642 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1643 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1644 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1645 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1646 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1647 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1648 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1649 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1650 | { |
| 1651 | return gl::error(GL_INVALID_VALUE, false); |
| 1652 | } |
| 1653 | if (tex->getTarget() != GL_TEXTURE_CUBE_MAP) |
| 1654 | { |
| 1655 | return gl::error(GL_INVALID_OPERATION, false); |
| 1656 | } |
| 1657 | gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex); |
| 1658 | if (texcube->isCompressed(textarget, level)) |
| 1659 | { |
| 1660 | return gl::error(GL_INVALID_OPERATION, false); |
| 1661 | } |
| 1662 | } |
| 1663 | break; |
| 1664 | |
| 1665 | default: |
| 1666 | return gl::error(GL_INVALID_ENUM, false); |
| 1667 | } |
| 1668 | } |
| 1669 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1670 | return true; |
| 1671 | } |
| 1672 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1673 | bool ValidateGetUniformBase(const gl::Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1674 | { |
| 1675 | if (program == 0) |
| 1676 | { |
| 1677 | return gl::error(GL_INVALID_VALUE, false); |
| 1678 | } |
| 1679 | |
| 1680 | gl::Program *programObject = context->getProgram(program); |
| 1681 | |
| 1682 | if (!programObject || !programObject->isLinked()) |
| 1683 | { |
| 1684 | return gl::error(GL_INVALID_OPERATION, false); |
| 1685 | } |
| 1686 | |
| 1687 | gl::ProgramBinary *programBinary = programObject->getProgramBinary(); |
| 1688 | if (!programBinary) |
| 1689 | { |
| 1690 | return gl::error(GL_INVALID_OPERATION, false); |
| 1691 | } |
| 1692 | |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1693 | if (!programBinary->isValidUniformLocation(location)) |
| 1694 | { |
| 1695 | return gl::error(GL_INVALID_OPERATION, false); |
| 1696 | } |
| 1697 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1698 | return true; |
| 1699 | } |
| 1700 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1701 | bool ValidateGetUniformfv(const gl::Context *context, GLuint program, GLint location, GLfloat* params) |
| 1702 | { |
| 1703 | return ValidateGetUniformBase(context, program, location); |
| 1704 | } |
| 1705 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1706 | bool ValidateGetUniformiv(const gl::Context *context, GLuint program, GLint location, GLint* params) |
| 1707 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1708 | return ValidateGetUniformBase(context, program, location); |
| 1709 | } |
| 1710 | |
| 1711 | static bool ValidateSizedGetUniform(const gl::Context *context, GLuint program, GLint location, GLsizei bufSize) |
| 1712 | { |
| 1713 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1714 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1715 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1716 | } |
| 1717 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1718 | gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary(); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1719 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1720 | // sized queries -- ensure the provided buffer is large enough |
| 1721 | LinkedUniform *uniform = programBinary->getUniformByLocation(location); |
| 1722 | size_t requiredBytes = VariableExternalSize(uniform->type); |
| 1723 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1724 | { |
| 1725 | return gl::error(GL_INVALID_OPERATION, false); |
| 1726 | } |
| 1727 | |
| 1728 | return true; |
| 1729 | } |
| 1730 | |
| 1731 | bool ValidateGetnUniformfvEXT(const gl::Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params) |
| 1732 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1733 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | bool ValidateGetnUniformivEXT(const gl::Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params) |
| 1737 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1738 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1739 | } |
| 1740 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1741 | } |