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 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES.h" |
| 10 | #include "libANGLE/validationES2.h" |
| 11 | #include "libANGLE/validationES3.h" |
| 12 | #include "libANGLE/Context.h" |
| 13 | #include "libANGLE/Texture.h" |
| 14 | #include "libANGLE/Framebuffer.h" |
| 15 | #include "libANGLE/FramebufferAttachment.h" |
| 16 | #include "libANGLE/formatutils.h" |
| 17 | #include "libANGLE/Query.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 18 | #include "libANGLE/Program.h" |
| 19 | #include "libANGLE/Uniform.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/TransformFeedback.h" |
| 21 | #include "libANGLE/VertexArray.h" |
| 22 | #include "libANGLE/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 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 171 | bool ValidImageSize(const Context *context, GLenum target, GLint level, |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 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 | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 193 | bool ValidCompressedImageSize(const 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 | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 227 | bool ValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 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 |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 240 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 241 | return false; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 242 | } |
| 243 | else |
| 244 | { |
| 245 | // No shader/program object has this ID |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 246 | context->recordError(Error(GL_INVALID_VALUE)); |
| 247 | return false; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 251 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 252 | { |
| 253 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 254 | { |
| 255 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
| 256 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 257 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 258 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 259 | context->recordError(Error(GL_INVALID_VALUE)); |
| 260 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | switch (attachment) |
| 266 | { |
| 267 | case GL_DEPTH_ATTACHMENT: |
| 268 | case GL_STENCIL_ATTACHMENT: |
| 269 | break; |
| 270 | |
| 271 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 272 | if (context->getClientVersion() < 3) |
| 273 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 274 | context->recordError(Error(GL_INVALID_ENUM)); |
| 275 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 276 | } |
| 277 | break; |
| 278 | |
| 279 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 280 | context->recordError(Error(GL_INVALID_ENUM)); |
| 281 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | return true; |
| 286 | } |
| 287 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 288 | bool ValidateRenderbufferStorageParametersBase(gl::Context *context, GLenum target, GLsizei samples, |
| 289 | GLenum internalformat, GLsizei width, GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 290 | { |
| 291 | switch (target) |
| 292 | { |
| 293 | case GL_RENDERBUFFER: |
| 294 | break; |
| 295 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 296 | context->recordError(Error(GL_INVALID_ENUM)); |
| 297 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | if (width < 0 || height < 0 || samples < 0) |
| 301 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 302 | context->recordError(Error(GL_INVALID_VALUE)); |
| 303 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 304 | } |
| 305 | |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 306 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 307 | if (!formatCaps.renderable) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 308 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 309 | context->recordError(Error(GL_INVALID_ENUM)); |
| 310 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 314 | // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 315 | // only sized internal formats. |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 316 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 317 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 318 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 319 | context->recordError(Error(GL_INVALID_ENUM)); |
| 320 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 321 | } |
| 322 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 323 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 324 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 325 | context->recordError(Error(GL_INVALID_VALUE)); |
| 326 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 327 | } |
| 328 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 329 | GLuint handle = context->getState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 330 | if (handle == 0) |
| 331 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 332 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 333 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | return true; |
| 337 | } |
| 338 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 339 | bool ValidateRenderbufferStorageParametersANGLE(gl::Context *context, GLenum target, GLsizei samples, |
| 340 | GLenum internalformat, GLsizei width, GLsizei height) |
| 341 | { |
Austin Kinross | d2cf3ad | 2015-01-07 14:00:30 -0800 | [diff] [blame] | 342 | ASSERT(samples == 0 || context->getExtensions().framebufferMultisample); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 343 | |
| 344 | // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal |
| 345 | // to MAX_SAMPLES_ANGLE (Context::getExtensions().maxSamples) otherwise GL_INVALID_VALUE is |
| 346 | // generated. |
| 347 | if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples) |
| 348 | { |
| 349 | context->recordError(Error(GL_INVALID_VALUE)); |
| 350 | return false; |
| 351 | } |
| 352 | |
| 353 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 354 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 355 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 356 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 357 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 358 | { |
| 359 | context->recordError(Error(GL_OUT_OF_MEMORY)); |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, height); |
| 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 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 371 | context->recordError(Error(GL_INVALID_ENUM)); |
| 372 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 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 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 380 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 381 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 384 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 385 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 386 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 387 | } |
| 388 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 389 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 390 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 391 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 392 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 393 | if (renderbuffer != 0) |
| 394 | { |
| 395 | if (!context->getRenderbuffer(renderbuffer)) |
| 396 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 397 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 398 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 402 | return true; |
| 403 | } |
| 404 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 405 | static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer, |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 406 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 407 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1) |
| 408 | { |
| 409 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || |
| 410 | dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() || |
| 411 | srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight()) |
| 412 | { |
| 413 | return true; |
| 414 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 415 | else if (context->getState().isScissorTestEnabled()) |
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 | const Rectangle &scissor = context->getState().getScissor(); |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 418 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 419 | return scissor.x > 0 || scissor.y > 0 || |
| 420 | scissor.width < writeBuffer->getWidth() || |
| 421 | scissor.height < writeBuffer->getHeight(); |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 422 | } |
| 423 | else |
| 424 | { |
| 425 | return false; |
| 426 | } |
| 427 | } |
| 428 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 429 | 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] | 430 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, |
| 431 | GLenum filter, bool fromAngleExtension) |
| 432 | { |
| 433 | switch (filter) |
| 434 | { |
| 435 | case GL_NEAREST: |
| 436 | break; |
| 437 | case GL_LINEAR: |
| 438 | if (fromAngleExtension) |
| 439 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 440 | context->recordError(Error(GL_INVALID_ENUM)); |
| 441 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 442 | } |
| 443 | break; |
| 444 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 445 | context->recordError(Error(GL_INVALID_ENUM)); |
| 446 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 450 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 451 | context->recordError(Error(GL_INVALID_VALUE)); |
| 452 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | if (mask == 0) |
| 456 | { |
| 457 | // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no |
| 458 | // buffers are copied. |
| 459 | return false; |
| 460 | } |
| 461 | |
| 462 | if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)) |
| 463 | { |
| 464 | ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 465 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 466 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 470 | // color buffer, leaving only nearest being unfiltered from above |
| 471 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 472 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 473 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 474 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 475 | } |
| 476 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 477 | if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 478 | { |
| 479 | if (fromAngleExtension) |
| 480 | { |
| 481 | ERR("Blits with the same source and destination framebuffer are not supported by this " |
| 482 | "implementation."); |
| 483 | } |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 484 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 485 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 486 | } |
| 487 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 488 | gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 489 | gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 490 | |
| 491 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 492 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 493 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 494 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 495 | } |
| 496 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 497 | if (!readFramebuffer->checkStatus(context->getData())) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 498 | { |
| 499 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 500 | return false; |
| 501 | } |
| 502 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 503 | if (!drawFramebuffer->checkStatus(context->getData())) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 504 | { |
| 505 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 506 | return false; |
| 507 | } |
| 508 | |
| 509 | if (drawFramebuffer->getSamples(context->getData()) != 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 510 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 511 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 512 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 513 | } |
| 514 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 515 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 516 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 517 | if (mask & GL_COLOR_BUFFER_BIT) |
| 518 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 519 | gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 520 | gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 521 | |
| 522 | if (readColorBuffer && drawColorBuffer) |
| 523 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 524 | GLenum readInternalFormat = readColorBuffer->getInternalFormat(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 525 | const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 526 | |
| 527 | for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++) |
| 528 | { |
| 529 | if (drawFramebuffer->isEnabledColorAttachment(i)) |
| 530 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 531 | GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getInternalFormat(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 532 | const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 533 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 534 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 535 | // 1) If the read buffer is fixed point format, the draw buffer must be as well |
| 536 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well |
| 537 | // 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] | 538 | if ( (readFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || readFormatInfo.componentType == GL_SIGNED_NORMALIZED) && |
| 539 | !(drawFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || drawFormatInfo.componentType == GL_SIGNED_NORMALIZED)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 540 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 541 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 542 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 543 | } |
| 544 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 545 | if (readFormatInfo.componentType == GL_UNSIGNED_INT && drawFormatInfo.componentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 546 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 547 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 548 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 549 | } |
| 550 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 551 | if (readFormatInfo.componentType == GL_INT && drawFormatInfo.componentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 552 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 553 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 554 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 555 | } |
| 556 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 557 | if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 558 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 559 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 560 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 565 | 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] | 566 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 567 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 568 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | if (fromAngleExtension) |
| 572 | { |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 573 | FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 574 | if (!readColorAttachment || |
| 575 | (!(readColorAttachment->type() == GL_TEXTURE && readColorAttachment->getTextureImageIndex()->type == GL_TEXTURE_2D) && |
| 576 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 577 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 578 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 579 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 580 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 584 | { |
| 585 | if (drawFramebuffer->isEnabledColorAttachment(colorAttachment)) |
| 586 | { |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 587 | FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment); |
| 588 | ASSERT(attachment); |
| 589 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 590 | if (!(attachment->type() == GL_TEXTURE && attachment->getTextureImageIndex()->type == GL_TEXTURE_2D) && |
| 591 | attachment->type() != GL_RENDERBUFFER && |
| 592 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 593 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 594 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 595 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Jamie Madill | f8f18f0 | 2014-10-02 10:44:17 -0400 | [diff] [blame] | 598 | // Return an error if the destination formats do not match |
| 599 | if (attachment->getInternalFormat() != readColorBuffer->getInternalFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 600 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 601 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 602 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | } |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 606 | |
| 607 | int readSamples = readFramebuffer->getSamples(context->getData()); |
| 608 | |
| 609 | if (readSamples != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer, |
| 610 | srcX0, srcY0, srcX1, srcY1, |
| 611 | dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 612 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 613 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 614 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 620 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
| 621 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 622 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 623 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 624 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 625 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 626 | gl::FramebufferAttachment *readBuffer = readFramebuffer->getAttachment(attachments[i]); |
| 627 | gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getAttachment(attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 628 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 629 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 630 | { |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 631 | if (readBuffer->getInternalFormat() != drawBuffer->getInternalFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 632 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 633 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 634 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 635 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 636 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 637 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 638 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 639 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 640 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 641 | } |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 642 | |
| 643 | if (fromAngleExtension) |
| 644 | { |
| 645 | if (IsPartialBlit(context, readBuffer, drawBuffer, |
| 646 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
| 647 | { |
| 648 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
| 649 | context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted |
| 650 | return false; |
| 651 | } |
| 652 | |
| 653 | if (readBuffer->getSamples() != 0 || drawBuffer->getSamples() != 0) |
| 654 | { |
| 655 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 656 | return false; |
| 657 | } |
| 658 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | return true; |
| 664 | } |
| 665 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 666 | bool ValidateGetVertexAttribParameters(Context *context, GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 667 | { |
| 668 | switch (pname) |
| 669 | { |
| 670 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 671 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 672 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 673 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 674 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 675 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 676 | case GL_CURRENT_VERTEX_ATTRIB: |
| 677 | return true; |
| 678 | |
| 679 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 680 | // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses |
| 681 | // the same constant. |
| 682 | META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE); |
| 683 | return true; |
| 684 | |
| 685 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 686 | if (context->getClientVersion() < 3) |
| 687 | { |
| 688 | context->recordError(Error(GL_INVALID_ENUM)); |
| 689 | return false; |
| 690 | } |
| 691 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 692 | |
| 693 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 694 | context->recordError(Error(GL_INVALID_ENUM)); |
| 695 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 699 | bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 700 | { |
| 701 | switch (pname) |
| 702 | { |
| 703 | case GL_TEXTURE_WRAP_R: |
| 704 | case GL_TEXTURE_SWIZZLE_R: |
| 705 | case GL_TEXTURE_SWIZZLE_G: |
| 706 | case GL_TEXTURE_SWIZZLE_B: |
| 707 | case GL_TEXTURE_SWIZZLE_A: |
| 708 | case GL_TEXTURE_BASE_LEVEL: |
| 709 | case GL_TEXTURE_MAX_LEVEL: |
| 710 | case GL_TEXTURE_COMPARE_MODE: |
| 711 | case GL_TEXTURE_COMPARE_FUNC: |
| 712 | case GL_TEXTURE_MIN_LOD: |
| 713 | case GL_TEXTURE_MAX_LOD: |
| 714 | if (context->getClientVersion() < 3) |
| 715 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 716 | context->recordError(Error(GL_INVALID_ENUM)); |
| 717 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 718 | } |
| 719 | break; |
| 720 | |
| 721 | default: break; |
| 722 | } |
| 723 | |
| 724 | switch (pname) |
| 725 | { |
| 726 | case GL_TEXTURE_WRAP_S: |
| 727 | case GL_TEXTURE_WRAP_T: |
| 728 | case GL_TEXTURE_WRAP_R: |
| 729 | switch (param) |
| 730 | { |
| 731 | case GL_REPEAT: |
| 732 | case GL_CLAMP_TO_EDGE: |
| 733 | case GL_MIRRORED_REPEAT: |
| 734 | return true; |
| 735 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 736 | context->recordError(Error(GL_INVALID_ENUM)); |
| 737 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | case GL_TEXTURE_MIN_FILTER: |
| 741 | switch (param) |
| 742 | { |
| 743 | case GL_NEAREST: |
| 744 | case GL_LINEAR: |
| 745 | case GL_NEAREST_MIPMAP_NEAREST: |
| 746 | case GL_LINEAR_MIPMAP_NEAREST: |
| 747 | case GL_NEAREST_MIPMAP_LINEAR: |
| 748 | case GL_LINEAR_MIPMAP_LINEAR: |
| 749 | return true; |
| 750 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 751 | context->recordError(Error(GL_INVALID_ENUM)); |
| 752 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 753 | } |
| 754 | break; |
| 755 | |
| 756 | case GL_TEXTURE_MAG_FILTER: |
| 757 | switch (param) |
| 758 | { |
| 759 | case GL_NEAREST: |
| 760 | case GL_LINEAR: |
| 761 | return true; |
| 762 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 763 | context->recordError(Error(GL_INVALID_ENUM)); |
| 764 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 765 | } |
| 766 | break; |
| 767 | |
| 768 | case GL_TEXTURE_USAGE_ANGLE: |
| 769 | switch (param) |
| 770 | { |
| 771 | case GL_NONE: |
| 772 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 773 | return true; |
| 774 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 775 | context->recordError(Error(GL_INVALID_ENUM)); |
| 776 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 777 | } |
| 778 | break; |
| 779 | |
| 780 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 781 | if (!context->getExtensions().textureFilterAnisotropic) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 782 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 783 | context->recordError(Error(GL_INVALID_ENUM)); |
| 784 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | // we assume the parameter passed to this validation method is truncated, not rounded |
| 788 | if (param < 1) |
| 789 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 790 | context->recordError(Error(GL_INVALID_VALUE)); |
| 791 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 792 | } |
| 793 | return true; |
| 794 | |
| 795 | case GL_TEXTURE_MIN_LOD: |
| 796 | case GL_TEXTURE_MAX_LOD: |
| 797 | // any value is permissible |
| 798 | return true; |
| 799 | |
| 800 | case GL_TEXTURE_COMPARE_MODE: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 801 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 802 | switch (param) |
| 803 | { |
| 804 | case GL_NONE: |
| 805 | case GL_COMPARE_REF_TO_TEXTURE: |
| 806 | return true; |
| 807 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 808 | context->recordError(Error(GL_INVALID_ENUM)); |
| 809 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 810 | } |
| 811 | break; |
| 812 | |
| 813 | case GL_TEXTURE_COMPARE_FUNC: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 814 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 815 | switch (param) |
| 816 | { |
| 817 | case GL_LEQUAL: |
| 818 | case GL_GEQUAL: |
| 819 | case GL_LESS: |
| 820 | case GL_GREATER: |
| 821 | case GL_EQUAL: |
| 822 | case GL_NOTEQUAL: |
| 823 | case GL_ALWAYS: |
| 824 | case GL_NEVER: |
| 825 | return true; |
| 826 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 827 | context->recordError(Error(GL_INVALID_ENUM)); |
| 828 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 829 | } |
| 830 | break; |
| 831 | |
| 832 | case GL_TEXTURE_SWIZZLE_R: |
| 833 | case GL_TEXTURE_SWIZZLE_G: |
| 834 | case GL_TEXTURE_SWIZZLE_B: |
| 835 | case GL_TEXTURE_SWIZZLE_A: |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 836 | switch (param) |
| 837 | { |
| 838 | case GL_RED: |
| 839 | case GL_GREEN: |
| 840 | case GL_BLUE: |
| 841 | case GL_ALPHA: |
| 842 | case GL_ZERO: |
| 843 | case GL_ONE: |
| 844 | return true; |
| 845 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 846 | context->recordError(Error(GL_INVALID_ENUM)); |
| 847 | return false; |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 848 | } |
| 849 | break; |
| 850 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 851 | case GL_TEXTURE_BASE_LEVEL: |
| 852 | case GL_TEXTURE_MAX_LEVEL: |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 853 | if (param < 0) |
| 854 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 855 | context->recordError(Error(GL_INVALID_VALUE)); |
| 856 | return false; |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 857 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 858 | return true; |
| 859 | |
| 860 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 861 | context->recordError(Error(GL_INVALID_ENUM)); |
| 862 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 866 | bool ValidateSamplerObjectParameter(gl::Context *context, GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 867 | { |
| 868 | switch (pname) |
| 869 | { |
| 870 | case GL_TEXTURE_MIN_FILTER: |
| 871 | case GL_TEXTURE_MAG_FILTER: |
| 872 | case GL_TEXTURE_WRAP_S: |
| 873 | case GL_TEXTURE_WRAP_T: |
| 874 | case GL_TEXTURE_WRAP_R: |
| 875 | case GL_TEXTURE_MIN_LOD: |
| 876 | case GL_TEXTURE_MAX_LOD: |
| 877 | case GL_TEXTURE_COMPARE_MODE: |
| 878 | case GL_TEXTURE_COMPARE_FUNC: |
| 879 | return true; |
| 880 | |
| 881 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 882 | context->recordError(Error(GL_INVALID_ENUM)); |
| 883 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 887 | bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height, |
| 888 | GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels) |
| 889 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 890 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 891 | ASSERT(framebuffer); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 892 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 893 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 894 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 895 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 896 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 897 | } |
| 898 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 899 | if (context->getState().getReadFramebuffer()->id() != 0 && |
| 900 | framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 901 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 902 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 903 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 904 | } |
| 905 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 906 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 907 | if (!readBuffer) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 908 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 909 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 910 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 911 | } |
| 912 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 913 | GLenum currentFormat = framebuffer->getImplementationColorReadFormat(); |
| 914 | GLenum currentType = framebuffer->getImplementationColorReadType(); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 915 | GLenum currentInternalFormat = readBuffer->getInternalFormat(); |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 916 | GLuint clientVersion = context->getClientVersion(); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 917 | |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 918 | bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) : |
| 919 | ValidES3ReadFormatType(context, currentInternalFormat, format, type); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 920 | |
| 921 | if (!(currentFormat == format && currentType == type) && !validReadFormat) |
| 922 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 923 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 924 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 925 | } |
| 926 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 927 | GLenum sizedInternalFormat = GetSizedInternalFormat(format, type); |
| 928 | const InternalFormat &sizedFormatInfo = GetInternalFormatInfo(sizedInternalFormat); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 929 | |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 930 | GLsizei outputPitch = sizedFormatInfo.computeRowPitch(type, width, context->getState().getPackAlignment(), 0); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 931 | // sized query sanity check |
| 932 | if (bufSize) |
| 933 | { |
| 934 | int requiredSize = outputPitch * height; |
| 935 | if (requiredSize > *bufSize) |
| 936 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 937 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 938 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
| 942 | return true; |
| 943 | } |
| 944 | |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 945 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 946 | { |
| 947 | if (!ValidQueryType(context, target)) |
| 948 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 949 | context->recordError(Error(GL_INVALID_ENUM)); |
| 950 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | if (id == 0) |
| 954 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 955 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 956 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 960 | // of zero, if the active query object name for <target> is non-zero (for the |
| 961 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 962 | // the active query for either target is non-zero), if <id> is the name of an |
| 963 | // existing query object whose type does not match <target>, or if <id> is the |
| 964 | // active query object name for any query type, the error INVALID_OPERATION is |
| 965 | // generated. |
| 966 | |
| 967 | // Ensure no other queries are active |
| 968 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 969 | // separately that: |
| 970 | // a) The query ID passed is not the current active query for any target/type |
| 971 | // b) There are no active queries for the requested target (and in the case |
| 972 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 973 | // no query may be active for either if glBeginQuery targets either. |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 974 | if (context->getState().isQueryActive()) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 975 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 976 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 977 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | Query *queryObject = context->getQuery(id, true, target); |
| 981 | |
| 982 | // check that name was obtained with glGenQueries |
| 983 | if (!queryObject) |
| 984 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 985 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 986 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | // check for type mismatch |
| 990 | if (queryObject->getType() != target) |
| 991 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 992 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 993 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | return true; |
| 997 | } |
| 998 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 999 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 1000 | { |
| 1001 | if (!ValidQueryType(context, target)) |
| 1002 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1003 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1004 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1007 | const Query *queryObject = context->getState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1008 | |
| 1009 | if (queryObject == NULL) |
| 1010 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1011 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1012 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1015 | return true; |
| 1016 | } |
| 1017 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1018 | static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType, |
| 1019 | GLint location, GLsizei count, LinkedUniform **uniformOut) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1020 | { |
| 1021 | if (count < 0) |
| 1022 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1023 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1024 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1025 | } |
| 1026 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1027 | gl::Program *program = context->getState().getProgram(); |
| 1028 | if (!program) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1029 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1030 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1031 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | if (location == -1) |
| 1035 | { |
| 1036 | // Silently ignore the uniform command |
| 1037 | return false; |
| 1038 | } |
| 1039 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1040 | if (!program->isValidUniformLocation(location)) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1041 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1042 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1043 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1044 | } |
| 1045 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1046 | LinkedUniform *uniform = program->getUniformByLocation(location); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1047 | |
| 1048 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
| 1049 | if (uniform->elementCount() == 1 && count > 1) |
| 1050 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1051 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1052 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | *uniformOut = uniform; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1056 | return true; |
| 1057 | } |
| 1058 | |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1059 | bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count) |
| 1060 | { |
| 1061 | // Check for ES3 uniform entry points |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1062 | if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1063 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1064 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1065 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1066 | } |
| 1067 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1068 | LinkedUniform *uniform = NULL; |
| 1069 | if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform)) |
| 1070 | { |
| 1071 | return false; |
| 1072 | } |
| 1073 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1074 | GLenum targetBoolType = VariableBoolVectorType(uniformType); |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 1075 | bool samplerUniformCheck = (IsSamplerType(uniform->type) && uniformType == GL_INT); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1076 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 1077 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1078 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1079 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count, |
| 1086 | GLboolean transpose) |
| 1087 | { |
| 1088 | // Check for ES3 uniform entry points |
| 1089 | int rows = VariableRowCount(matrixType); |
| 1090 | int cols = VariableColumnCount(matrixType); |
| 1091 | if (rows != cols && context->getClientVersion() < 3) |
| 1092 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1093 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1094 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | if (transpose != GL_FALSE && context->getClientVersion() < 3) |
| 1098 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1099 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1100 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1103 | LinkedUniform *uniform = NULL; |
| 1104 | if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform)) |
| 1105 | { |
| 1106 | return false; |
| 1107 | } |
| 1108 | |
| 1109 | if (uniform->type != matrixType) |
| 1110 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1111 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1112 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1116 | } |
| 1117 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1118 | bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
| 1119 | { |
| 1120 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 1121 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1122 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1123 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 1127 | { |
| 1128 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 1129 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1130 | if (colorAttachment >= context->getCaps().maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1131 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1132 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1133 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | switch (pname) |
| 1138 | { |
| 1139 | case GL_TEXTURE_BINDING_2D: |
| 1140 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1141 | case GL_TEXTURE_BINDING_3D: |
| 1142 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1143 | if (context->getState().getActiveSampler() >= context->getCaps().maxCombinedTextureImageUnits) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1144 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1145 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1146 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1147 | } |
| 1148 | break; |
| 1149 | |
| 1150 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1151 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1152 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1153 | Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1154 | ASSERT(framebuffer); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1155 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1156 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1157 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1158 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1159 | } |
| 1160 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 1161 | FramebufferAttachment *attachment = framebuffer->getReadColorbuffer(); |
| 1162 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1163 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1164 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1165 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | break; |
| 1169 | |
| 1170 | default: |
| 1171 | break; |
| 1172 | } |
| 1173 | |
| 1174 | // pname is valid, but there are no parameters to return |
| 1175 | if (numParams == 0) |
| 1176 | { |
| 1177 | return false; |
| 1178 | } |
| 1179 | |
| 1180 | return true; |
| 1181 | } |
| 1182 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1183 | bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage, |
| 1184 | GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, |
| 1185 | GLint border, GLenum *textureFormatOut) |
| 1186 | { |
| 1187 | |
| 1188 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1189 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1190 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1191 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0) |
| 1195 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1196 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1197 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1201 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1202 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1203 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | if (border != 0) |
| 1207 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1208 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1209 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | if (!ValidMipLevel(context, target, level)) |
| 1213 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1214 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1215 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1216 | } |
| 1217 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1218 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1219 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1220 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1221 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1222 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1223 | } |
| 1224 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1225 | if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1226 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1227 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1228 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1229 | } |
| 1230 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1231 | const gl::Caps &caps = context->getCaps(); |
| 1232 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1233 | GLuint maxDimension = 0; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1234 | switch (target) |
| 1235 | { |
| 1236 | case GL_TEXTURE_2D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1237 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1238 | break; |
| 1239 | |
| 1240 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1241 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1242 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1243 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1244 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1245 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1246 | maxDimension = caps.maxCubeMapTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1247 | break; |
| 1248 | |
| 1249 | case GL_TEXTURE_2D_ARRAY: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1250 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1251 | break; |
| 1252 | |
| 1253 | case GL_TEXTURE_3D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1254 | maxDimension = caps.max3DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1255 | break; |
| 1256 | |
| 1257 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1258 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1259 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1262 | gl::Texture *texture = context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1263 | if (!texture) |
| 1264 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1265 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1266 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | if (texture->isImmutable() && !isSubImage) |
| 1270 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1271 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1272 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1275 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1276 | |
| 1277 | if (formatInfo.depthBits > 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1278 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1279 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1280 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1281 | } |
| 1282 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1283 | if (formatInfo.compressed && !ValidCompressedImageSize(context, internalformat, width, height)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1284 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1285 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1286 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | if (isSubImage) |
| 1290 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1291 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 1292 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 1293 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1294 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1295 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1296 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1297 | } |
| 1298 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1299 | else |
| 1300 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1301 | if (IsCubeMapTextureTarget(target) && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1302 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1303 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1304 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1305 | } |
| 1306 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1307 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1308 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1309 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1310 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | int maxLevelDimension = (maxDimension >> level); |
| 1314 | if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension) |
| 1315 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1316 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1317 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1318 | } |
| 1319 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1320 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1321 | *textureFormatOut = texture->getInternalFormat(target, level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1322 | return true; |
| 1323 | } |
| 1324 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1325 | static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsizei maxVertex, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1326 | { |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1327 | switch (mode) |
| 1328 | { |
| 1329 | case GL_POINTS: |
| 1330 | case GL_LINES: |
| 1331 | case GL_LINE_LOOP: |
| 1332 | case GL_LINE_STRIP: |
| 1333 | case GL_TRIANGLES: |
| 1334 | case GL_TRIANGLE_STRIP: |
| 1335 | case GL_TRIANGLE_FAN: |
| 1336 | break; |
| 1337 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1338 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1339 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1340 | } |
| 1341 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1342 | if (count < 0) |
| 1343 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1344 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1345 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1348 | const State &state = context->getState(); |
| 1349 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1350 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1351 | if (state.hasMappedBuffer(GL_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1352 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1353 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1354 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1357 | const gl::DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1358 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1359 | state.getStencilRef() != state.getStencilBackRef() || |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1360 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 1361 | { |
| 1362 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. |
| 1363 | // See Section 6.10 of the WebGL 1.0 spec |
| 1364 | ERR("This ANGLE implementation does not support separate front/back stencil " |
| 1365 | "writemasks, reference values, or stencil mask values."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1366 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1367 | return false; |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1368 | } |
| 1369 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1370 | const gl::Framebuffer *fbo = state.getDrawFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1371 | if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1372 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1373 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1374 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1375 | } |
| 1376 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1377 | gl::Program *program = state.getProgram(); |
| 1378 | if (!program) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1379 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1380 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1381 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1382 | } |
| 1383 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1384 | if (!program->validateSamplers(NULL, context->getCaps())) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1385 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1386 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1387 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1390 | // Buffer validations |
| 1391 | const VertexArray *vao = state.getVertexArray(); |
| 1392 | for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 1393 | { |
| 1394 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1395 | bool attribActive = (program->getSemanticIndex(attributeIndex) != -1); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1396 | if (attribActive && attrib.enabled) |
| 1397 | { |
| 1398 | gl::Buffer *buffer = attrib.buffer.get(); |
| 1399 | |
| 1400 | if (buffer) |
| 1401 | { |
| 1402 | GLint64 attribStride = static_cast<GLint64>(ComputeVertexAttributeStride(attrib)); |
| 1403 | GLint64 maxVertexElement = 0; |
| 1404 | |
| 1405 | if (attrib.divisor > 0) |
| 1406 | { |
| 1407 | maxVertexElement = static_cast<GLint64>(primcount) / static_cast<GLint64>(attrib.divisor); |
| 1408 | } |
| 1409 | else |
| 1410 | { |
| 1411 | maxVertexElement = static_cast<GLint64>(maxVertex); |
| 1412 | } |
| 1413 | |
| 1414 | GLint64 attribDataSize = maxVertexElement * attribStride; |
| 1415 | |
| 1416 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 1417 | // We can return INVALID_OPERATION if our vertex attribute does not have |
| 1418 | // enough backing data. |
| 1419 | if (attribDataSize > buffer->getSize()) |
| 1420 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1421 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1422 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | else if (attrib.pointer == NULL) |
| 1426 | { |
| 1427 | // This is an application error that would normally result in a crash, |
| 1428 | // but we catch it and return an error |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1429 | context->recordError(Error(GL_INVALID_OPERATION, "An enabled vertex array has no buffer and no pointer.")); |
| 1430 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1435 | // No-op if zero count |
| 1436 | return (count > 0); |
| 1437 | } |
| 1438 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1439 | bool ValidateDrawArrays(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1440 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1441 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1442 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1443 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1444 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1445 | } |
| 1446 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1447 | const State &state = context->getState(); |
| 1448 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1449 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() && |
| 1450 | curTransformFeedback->getDrawMode() != mode) |
| 1451 | { |
| 1452 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 1453 | // that does not match the current transform feedback object's draw mode (if transform feedback |
| 1454 | // is active), (3.0.2, section 2.14, pg 86) |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1455 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1456 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1457 | } |
| 1458 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1459 | if (!ValidateDrawBase(context, mode, count, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1460 | { |
| 1461 | return false; |
| 1462 | } |
| 1463 | |
| 1464 | return true; |
| 1465 | } |
| 1466 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1467 | bool ValidateDrawArraysInstanced(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1468 | { |
| 1469 | if (primcount < 0) |
| 1470 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1471 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1472 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1473 | } |
| 1474 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1475 | if (!ValidateDrawArrays(context, mode, first, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1476 | { |
| 1477 | return false; |
| 1478 | } |
| 1479 | |
| 1480 | // No-op if zero primitive count |
| 1481 | return (primcount > 0); |
| 1482 | } |
| 1483 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1484 | static bool ValidateDrawInstancedANGLE(Context *context) |
| 1485 | { |
| 1486 | // Verify there is at least one active attribute with a divisor of zero |
| 1487 | const gl::State& state = context->getState(); |
| 1488 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1489 | gl::Program *program = state.getProgram(); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1490 | |
| 1491 | const VertexArray *vao = state.getVertexArray(); |
| 1492 | for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 1493 | { |
| 1494 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1495 | bool active = (program->getSemanticIndex(attributeIndex) != -1); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1496 | if (active && attrib.divisor == 0) |
| 1497 | { |
| 1498 | return true; |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | context->recordError(Error(GL_INVALID_OPERATION, "ANGLE_instanced_arrays requires that at least one active attribute" |
| 1503 | "has a divisor of zero.")); |
| 1504 | return false; |
| 1505 | } |
| 1506 | |
| 1507 | bool ValidateDrawArraysInstancedANGLE(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
| 1508 | { |
| 1509 | if (!ValidateDrawInstancedANGLE(context)) |
| 1510 | { |
| 1511 | return false; |
| 1512 | } |
| 1513 | |
| 1514 | return ValidateDrawArraysInstanced(context, mode, first, count, primcount); |
| 1515 | } |
| 1516 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1517 | bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum type, |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1518 | const GLvoid* indices, GLsizei primcount, rx::RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1519 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1520 | switch (type) |
| 1521 | { |
| 1522 | case GL_UNSIGNED_BYTE: |
| 1523 | case GL_UNSIGNED_SHORT: |
| 1524 | break; |
| 1525 | case GL_UNSIGNED_INT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1526 | if (!context->getExtensions().elementIndexUint) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1527 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1528 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1529 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1530 | } |
| 1531 | break; |
| 1532 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1533 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1534 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1535 | } |
| 1536 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1537 | const State &state = context->getState(); |
| 1538 | |
| 1539 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1540 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused()) |
| 1541 | { |
| 1542 | // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced |
| 1543 | // while transform feedback is active, (3.0.2, section 2.14, pg 86) |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1544 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1545 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1549 | if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1550 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1551 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1552 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1555 | const gl::VertexArray *vao = state.getVertexArray(); |
| 1556 | const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
| 1557 | if (!indices && !elementArrayBuffer) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1558 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1559 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1560 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1561 | } |
| 1562 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1563 | if (elementArrayBuffer) |
| 1564 | { |
| 1565 | const gl::Type &typeInfo = gl::GetTypeInfo(type); |
| 1566 | |
| 1567 | GLint64 offset = reinterpret_cast<GLint64>(indices); |
| 1568 | GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset; |
| 1569 | |
| 1570 | // check for integer overflows |
| 1571 | if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) || |
| 1572 | byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max())) |
| 1573 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1574 | context->recordError(Error(GL_OUT_OF_MEMORY)); |
| 1575 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | // Check for reading past the end of the bound buffer object |
| 1579 | if (byteCount > elementArrayBuffer->getSize()) |
| 1580 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1581 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1582 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1583 | } |
| 1584 | } |
| 1585 | else if (!indices) |
| 1586 | { |
| 1587 | // Catch this programming error here |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1588 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1589 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1592 | // Use max index to validate if our vertex buffers are large enough for the pull. |
| 1593 | // TODO: offer fast path, with disabled index validation. |
| 1594 | // TODO: also disable index checking on back-ends that are robust to out-of-range accesses. |
| 1595 | if (elementArrayBuffer) |
| 1596 | { |
Jacek Caban | a5521de | 2014-10-01 17:23:46 +0200 | [diff] [blame] | 1597 | uintptr_t offset = reinterpret_cast<uintptr_t>(indices); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1598 | if (!elementArrayBuffer->getIndexRangeCache()->findRange(type, offset, count, indexRangeOut, NULL)) |
| 1599 | { |
Jamie Madill | 7246883 | 2015-01-05 15:03:18 -0500 | [diff] [blame] | 1600 | rx::BufferImpl *bufferImpl = elementArrayBuffer->getImplementation(); |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 1601 | const uint8_t *dataPointer = NULL; |
Jamie Madill | 7246883 | 2015-01-05 15:03:18 -0500 | [diff] [blame] | 1602 | Error error = bufferImpl->getData(&dataPointer); |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 1603 | if (error.isError()) |
| 1604 | { |
| 1605 | context->recordError(error); |
| 1606 | return false; |
| 1607 | } |
| 1608 | |
| 1609 | const uint8_t *offsetPointer = dataPointer + offset; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1610 | *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, offsetPointer, count); |
| 1611 | } |
| 1612 | } |
| 1613 | else |
| 1614 | { |
| 1615 | *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, indices, count); |
| 1616 | } |
| 1617 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1618 | if (!ValidateDrawBase(context, mode, count, static_cast<GLsizei>(indexRangeOut->end), primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1619 | { |
| 1620 | return false; |
| 1621 | } |
| 1622 | |
| 1623 | return true; |
| 1624 | } |
| 1625 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1626 | bool ValidateDrawElementsInstanced(Context *context, |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1627 | GLenum mode, GLsizei count, GLenum type, |
| 1628 | const GLvoid *indices, GLsizei primcount, |
| 1629 | rx::RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1630 | { |
| 1631 | if (primcount < 0) |
| 1632 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1633 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1634 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1635 | } |
| 1636 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1637 | if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1638 | { |
| 1639 | return false; |
| 1640 | } |
| 1641 | |
| 1642 | // No-op zero primitive count |
| 1643 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1644 | } |
| 1645 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1646 | bool ValidateDrawElementsInstancedANGLE(Context *context, GLenum mode, GLsizei count, GLenum type, |
| 1647 | const GLvoid *indices, GLsizei primcount, rx::RangeUI *indexRangeOut) |
| 1648 | { |
| 1649 | if (!ValidateDrawInstancedANGLE(context)) |
| 1650 | { |
| 1651 | return false; |
| 1652 | } |
| 1653 | |
| 1654 | return ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, indexRangeOut); |
| 1655 | } |
| 1656 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1657 | bool ValidateFramebufferTextureBase(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1658 | GLuint texture, GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1659 | { |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1660 | if (!ValidFramebufferTarget(target)) |
| 1661 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1662 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1663 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1667 | { |
| 1668 | return false; |
| 1669 | } |
| 1670 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1671 | if (texture != 0) |
| 1672 | { |
| 1673 | gl::Texture *tex = context->getTexture(texture); |
| 1674 | |
| 1675 | if (tex == NULL) |
| 1676 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1677 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1678 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | if (level < 0) |
| 1682 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1683 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1684 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1688 | const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
| 1689 | GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id(); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1690 | |
| 1691 | if (framebufferHandle == 0 || !framebuffer) |
| 1692 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1693 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1694 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | return true; |
| 1698 | } |
| 1699 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1700 | bool ValidateFramebufferTexture2D(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1701 | GLenum textarget, GLuint texture, GLint level) |
| 1702 | { |
| 1703 | // Attachments are required to be bound to level 0 in ES2 |
| 1704 | if (context->getClientVersion() < 3 && level != 0) |
| 1705 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1706 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1707 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1711 | { |
| 1712 | return false; |
| 1713 | } |
| 1714 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1715 | if (texture != 0) |
| 1716 | { |
| 1717 | gl::Texture *tex = context->getTexture(texture); |
| 1718 | ASSERT(tex); |
| 1719 | |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1720 | const gl::Caps &caps = context->getCaps(); |
| 1721 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1722 | switch (textarget) |
| 1723 | { |
| 1724 | case GL_TEXTURE_2D: |
| 1725 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1726 | if (level > gl::log2(caps.max2DTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1727 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1728 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1729 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1730 | } |
| 1731 | if (tex->getTarget() != GL_TEXTURE_2D) |
| 1732 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1733 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1734 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1735 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1736 | } |
| 1737 | break; |
| 1738 | |
| 1739 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1740 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1741 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1742 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1743 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1744 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1745 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1746 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1747 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1748 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1749 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1750 | } |
| 1751 | if (tex->getTarget() != GL_TEXTURE_CUBE_MAP) |
| 1752 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1753 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1754 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1755 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1756 | } |
| 1757 | break; |
| 1758 | |
| 1759 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1760 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1761 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1762 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1763 | |
| 1764 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(textarget, level)); |
| 1765 | if (internalFormatInfo.compressed) |
| 1766 | { |
| 1767 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1768 | return false; |
| 1769 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1770 | } |
| 1771 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1772 | return true; |
| 1773 | } |
| 1774 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1775 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1776 | { |
| 1777 | if (program == 0) |
| 1778 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1779 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1780 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1781 | } |
| 1782 | |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 1783 | if (!ValidProgram(context, program)) |
| 1784 | { |
| 1785 | return false; |
| 1786 | } |
| 1787 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1788 | gl::Program *programObject = context->getProgram(program); |
| 1789 | |
| 1790 | if (!programObject || !programObject->isLinked()) |
| 1791 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1792 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1793 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1794 | } |
| 1795 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1796 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1797 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1798 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1799 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1800 | } |
| 1801 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1802 | return true; |
| 1803 | } |
| 1804 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1805 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat* params) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1806 | { |
| 1807 | return ValidateGetUniformBase(context, program, location); |
| 1808 | } |
| 1809 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1810 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1811 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1812 | return ValidateGetUniformBase(context, program, location); |
| 1813 | } |
| 1814 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1815 | static bool ValidateSizedGetUniform(Context *context, GLuint program, GLint location, GLsizei bufSize) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1816 | { |
| 1817 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1818 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1819 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1820 | } |
| 1821 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 1822 | gl::Program *programObject = context->getProgram(program); |
| 1823 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1824 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1825 | // sized queries -- ensure the provided buffer is large enough |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1826 | LinkedUniform *uniform = programObject->getUniformByLocation(location); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1827 | size_t requiredBytes = VariableExternalSize(uniform->type); |
| 1828 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1829 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1830 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1831 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | return true; |
| 1835 | } |
| 1836 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1837 | bool ValidateGetnUniformfvEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1838 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1839 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1840 | } |
| 1841 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1842 | bool ValidateGetnUniformivEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1843 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1844 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1845 | } |
| 1846 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1847 | } |