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