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