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