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